MapMyFitness API-can';我不能让OAuth2在PHP中工作
全部, 我正在尝试使用MapMyFitness的API和OAuth2 下面是我正在使用的精简代码(类似于我成功用于连接Strava和RunKeeper API的代码): 当我运行这个时-MapMyFitness API-can';我不能让OAuth2在PHP中工作,php,json,api,oauth-2.0,mapmyfitness,Php,Json,Api,Oauth 2.0,Mapmyfitness,全部, 我正在尝试使用MapMyFitness的API和OAuth2 下面是我正在使用的精简代码(类似于我成功用于连接Strava和RunKeeper API的代码): 当我运行这个时-$json是空的,$responsecode是400,而不是200 我的请求显然有问题,但我不知道是什么…因此,感谢MapMyRun团队的帮助,以下是答案: $mapMyRun_authorization_code = "*****"; $client_id = "*********"; $client_secr
$json
是空的,$responsecode
是400,而不是200
我的请求显然有问题,但我不知道是什么…因此,感谢MapMyRun团队的帮助,以下是答案:
$mapMyRun_authorization_code = "*****";
$client_id = "*********";
$client_secret = "*************";
$url="https://oauth2-api.mapmyapi.com/v7.0/oauth2/access_token/";
$postfields = "grant_type=authorization_code&code=" . $mapMyRun_authorization_code . "&client_id=". $client_id . "&client_secret=" . $client_secret;
$headers = 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);
重要的更改-$postfields
不能是数组,您应该不包括curl\u setopt($ch,CURLOPT\u POST,true)代码>
希望这将对其他人有所帮助…{“错误”:“无效的授权”}获取此错误有助于解决紧急问题。
$mapMyRun_authorization_code = "*****";
$client_id = "*********";
$client_secret = "*************";
$url="https://oauth2-api.mapmyapi.com/v7.0/oauth2/access_token/";
$postfields = "grant_type=authorization_code&code=" . $mapMyRun_authorization_code . "&client_id=". $client_id . "&client_secret=" . $client_secret;
$headers = 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);