Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MapMyFitness API-can';我不能让OAuth2在PHP中工作_Php_Json_Api_Oauth 2.0_Mapmyfitness - Fatal编程技术网

MapMyFitness API-can';我不能让OAuth2在PHP中工作

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

全部,

我正在尝试使用MapMyFitness的API和OAuth2

下面是我正在使用的精简代码(类似于我成功用于连接Strava和RunKeeper API的代码):

当我运行这个时-
$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);