Good day,
Before getting back on Stackoverflow, I have been googling the entire afternoon without being really successful.
What I am trying to do is to get a token from myfox api by referring to their doc which says
A fresh token must be generated to be able to perform API calls. The token can be requested by calling the following method https://api.myfox.me/oauth2/token and providing the parameters below (through POST): client_id, client_secret, username, password and grant_type set to password.
Hence my code :
function getToken()
{
$clientID = "a65000ee0c57f2e37260e90c375c3";
$clientSecret = "MyLongSecretCode";
$exportFile = "myfile.txt";
$userName = "somebody@somewhere.com";
$userPass = "myPassword123";
$sourceWebsite = "https://api.myfox.me/oauth2/token?client_id=" . $clientID . "&client_secret=" . $clientSecret . "&username=" . $userName . "&password=" . $userPass . "&grant_type=password";
file_put_contents($exportFile, fopen($sourceWebsite , 'r'));
}
All I'm getting is a PHP error which says that the method is not allowed.
Any idea what I am missing here?
Many thanks for your kind help on this subject.
Edit 17.03.2017 :
I have been told by other users that I might be able to achieve this by using curl and it looks like, again, by reading the documentation that this is something that I can do :
A fresh token must be generated to be able to perform API calls. The token can be requested by calling the following method https://api.myfox.me/oauth2/token and providing the parameters below (through POST): client_id, client_secret, username, password and grant_type set to password. curl -u CLIENT_ID:CLIENT_SECRET https://api.myfox.me/oauth2/token -d 'grant_type=password&username=YOUR_USERNAME&password=YOUR_PASSWORD' or curl https://api.myfox.me/oauth2/token -d 'grant_type=password&client_id=CLIENT_ID&client_secret=CLIENT_SECRET&username=YOUR_USERNAME&password=YOUR_PASSWORD'
Now, for my question : is there a way to translate this curl -u query into a php instruction and to output the contents to a file out of it that would look like :
{"access_token":"********************************","expires_in":3600,"token_type":"Bearer","scope":null,"refresh_token":"********************************"}
Thanks again for your help.