2

我正在使用以下代码发布到我的时间线。我收到一个错误,显示在这篇文章的末尾。有任何想法吗?

<?php
......
$request = 'https://graph.facebook.com/oauth/access_token';
$grant_type = 'client_credentials';

$client_id = '1504901xxxxxxxx'; //FaceBook Developer App_id  LIVE
$client_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';  //Facebook Developer Api_secret LIVE

$postargs = 'grant_type=' . urlencode($grant_type) . '&client_id=' . $client_id . '&client_secret=' . $client_secret;

curl_setopt($session, CURLOPT_POST, true);
curl_setopt($session, CURLOPT_POSTFIELDS, $postargs);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($session);
preg_match('/access_token=(.*)/', $response, $match);
curl_close($session);

$access_token = trim($match[1]);
$Application = 'WTSO';
$User = '1504901xxxxxxxx'; /*this is the user id*/
$target_id = '1647886xxxxxxxx';

$api_url = 'https://api.facebook.com/method/stream.publish?';
$server_loc = 'https://wtso.com';
$logo = new stdClass();
$attachment = new stdClass();
$logo->type = 'image';
$logo->src = 'http://admin.wtso.com' . '/images/' . (($new_products['image_name']) ? $new_products['image_name'] : 'xx1235.jpg');
$logo->href = $facebook_bitly;
$attachment->name = ' '; //'WTSO Product Notification';
$attachment->caption = (!empty($new_products['products_short_description'])) ?    substr(strip_tags($new_products['products_short_description']), 0, 900) : $facebookText;
$attachment->description = '   ';
$attachment->href = $facebook_bitly;
$attachment->media = array($logo);

$message = (!empty($facebookText)) ? strip_tags($facebookText) : $new_products['products_name'];
$postargs2 = 'message=' . urlencode($message) . '&attachment=' . urlencode(json_encode($attachment)) . '&target_id=' . urlencode($target_id) . '&access_token=' . urlencode($access_token) . '&method=stream.publish'; 
$request2 = $api_url . $postargs2;

//Initiating a 2nd Curl instance
$session2 = curl_init($request2);
curl_setopt($session2, CURLOPT_HEADER, false);
curl_setopt($session2, CURLOPT_RETURNTRANSFER, true);
$response2 = curl_exec($session2);
curl_close($session2);
?>

我在 $response2 中从 Facebook 收到此错误

<error_code>200</error_code>
<error_msg>Insufficient permission to post to target on behalf of the viewer</error_msg>
4

0 回答 0