json - MapMyFitness API - can't get OAuth2 working in PHP -


All,

I'm trying to use the MapMyFitness API and OAuth2.

Here I am using the stripped down code (similar to the code I used to connect to the Strava and Runkeepers API):

  $ MapMyRun_authorization_code = "*****"; $ Client_id = "*********"; $ Client_secret = "************"; $ Url = "https://oauth2-api.mapmyapi.com/v7.0/oauth2/access_token/"; $ Postfields = Array ("grant_type" = & gt; "authorization_code", "client_id" => $ client_id, "client_secret" = & gt; $ client_secret; "code" => $ mapMyRun_authorization_code); $ Header = array ('API-key:'. $ Client_id); $ Ch = curl_init (); Curl_setopt ($ ch, CURLOPT_URL, $ url); Curl_setopt ($ CH, CURLOPT_RETURNTRANSFER, true); Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ postfields); Curl_setopt ($ ch, CURLOPT_POST, true); Curl_setopt ($ CH, CURLOPT_HTTPHEADER, $ headers); $ Json = curl_exec ($ ch); $ Responsecode = curl_getinfo ($ CH, CURLINFO_HTTP_CODE); Curl_close ($ ch);  

When I run it - $ json is empty, and $ responsecode is 400, not 200.

I'm clearly doing something wrong with your request, but I do not know whether ...

So, thanks for the help from the MapMyRun team, here is the answer:

  $ mapMyRun_authorization_code = "*****"; $ Client_id = "*********"; $ Client_secret = "************"; $ Url = "https://oauth2-api.mapmyapi.com/v7.0/oauth2/access_token/"; $ Postfield = "grant_type = official code and code =". $ MapMyRun_authorization_code "& Amp; client_id =". $ Client_id "& Amp; client_secret =" $ Client_secret; $ Header = array ('API-key:'. $ Client_id); $ Ch = curl_init (); Curl_setopt ($ ch, CURLOPT_URL, $ url); Curl_setopt ($ CH, CURLOPT_RETURNTRANSFER, true); Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ postfields); Curl_setopt ($ CH, CURLOPT_HTTPHEADER, $ headers); $ Json = curl_exec ($ ch); $ Responsecode = curl_getinfo ($ CH, CURLINFO_HTTP_CODE); Curl_close ($ ch);  

Important changes - $ postfields can not be an array, and you do not include < Code> curl_setopt ($ ch, CURLOPT_POST, true);

Hope this will be useful for anyone else ...


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -