全部,
我正在尝试使用 MapMyFitness 的 API 和 OAuth2。
这是我正在使用的精简代码(类似于我成功用于连接 Strava 和 RunKeeper API 的代码):
$mapMyRun_authorization_code = "*****";
$client_id = "*********";
$client_secret = "*************";
$url="https://oauth2-api.mapmyapi.com/v7.0/oauth2/access_token/";
$postfields = array(
"grant_type" => "authorization_code",
"client_id" => $client_id,
"client_secret" => $client_secret,
"code" => $mapMyRun_authorization_code
);
$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_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$json = curl_exec ($ch);
$responsecode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
当我运行这个 -$json
是空的,$responsecode
是 400,而不是 200。
我的请求显然做错了什么,但我不知道是什么......