我试图将照片上传到foursquare上的场地。
这是我的代码:
$image = "/assets/uploads/image/test.jpg";
$fields = json_encode(array("photo" => "@".$image));
$url = "https://api.foursquare.com/v2/photos/add?oauth_token=<my-oauth-token>&v=20160609&venueId=<my-venue-id>";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20000);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
//curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents($s));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: image/jpeg"));
$response = curl_exec($ch);
echo $response; exit;
和回复
{"meta":{"code":400,"errorType":"other","errorDetail":"Missing file upload","requestId":"57d6abf3498e0eb7f4639fa1"},"notifications":[{"type":"notificationTray","item":{"unreadCount":12}}],"response":{}}
显然我添加了海关令牌和场地ID。 我尝试通过卷曲添加一个提示,没问题。 我使用codeigniter和php5.4
有关foursquare API的更多信息 Null coalescing
感谢您的帮助!