我正在尝试使用strava api上传gpx文件。我已经获得了访问令牌,我正在使用这个脚本:
$actual_file= realpath('/.../../myfile.gpx');
$url="https://www.strava.com/api/v3/uploads";
$postfields = array(
"activity_type" => "ride",
"data_type" => "gpx",
"file" => '@' . $actual_file . ";type=application/xml"
);
$headers = array('Authorization: Bearer ' . $token);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec ($ch);
echo $response;
但我从strava得到的回复是{"message":"Bad Request","errors":[{"resource":"Upload","field":"file","code":"not a file"}]}
答案 0 :(得分:0)
我发现你应该使用"file" => curl_file_create($actual_file)
作为文件参数。这些参数也已过时(查看the new doc)。
我希望这会对某人有所帮助。我在查看PHP wrapper for Strava's API
时发现了它