使用API​​在VIADEO中发布链接

时间:2016-08-10 09:47:00

标签: php viadeo

我试图在使用它的API中发布viadeo网络链接,我使用了以下CURL代码。但它不起作用,我尝试用PHP作为我的服务器端代码。任何人都可以帮我解决这个问题。

API reference

$url = 'https://partners.viadeo.com/api/member/activity/share';
  $headers[] = 'Authorization: Bearer ' . $userArray['accessToken'];
  $headers[] = "Accept: language/json";
  $headers[] = 'Content-Type: application/JSON';


  $headers[] = 'X-CSRF-Token: ' . $token;

    $fields = array(
        'status' => "My Messafge",
        'url'   =>  "www.google.com"
    );


    //open connection
    $ch = curl_init();

    //set the url, number of POST vars, POST data

    curl_setopt($ch,CURLOPT_URL, $url);
    curl_setopt($ch,CURLOPT_POST, count($fields));
    curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query($fields));
    curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_HEADER, $headers);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    $result = curl_exec($ch);

但我得到的答复如下

    HTTP/1.1 406 Not Acceptable
Cache-control: no-cache="set-cookie"
Content-Type: application/json; charset=utf-8
Date: Wed, 10 Aug 2016 09:20:16 GMT
ETag: W/"79-LjiXR3TEaswtDc0NbPbnlA"
Server: nginx/1.8.1
Set-Cookie: AWSELB=EB652D71104D5A540BBD90F6B05BD98BEE3F41DAFDC50D85BE8FBFFCF095D7D78EB45C92813C3646048981782B8C4C76C884420B93A5B55954F394AA61798FEFC028CD93F8;PATH=/
X-Powered-By: Express
Content-Length: 121
Connection: keep-alive

{"error":"The provided Accept header is not acceptable. Try one of the following : application/json,multipart/form-data"}

1 个答案:

答案 0 :(得分:0)

尝试这样,它肯定会起作用

 $headers[] = "Accept: application/json";
 $headers[] = 'Content-Type: application/json';