【发布时间】:2017-12-06 04:16:39
【问题描述】:
我正在尝试使用 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"}]}
【问题讨论】: