我希望能夠發佈到用戶牆,(他編輯的消息)。但是,如果用戶沒有讓代表他發佈,然後我得到了以下錯誤:Facebook OAuthError - 無法將公開信息發佈到用戶的供稿
(#1) An error occured while creating the share|OAuthException
然後我讀,我可以再次把他送到我的日誌中的URL再次請求許可,但即使在允許之後它會發送相同的錯誤。
代碼:
try{...
$ret_obj = $facebook -> api('/' . $user_id . '/feed', 'POST', array('name' => $title, 'link' => $redirect_url, 'caption' => $ptnr_fb_caption, 'icon' => 'http://...logo-small.png', 'picture' => $ptnr_fb_img, 'message' => $desc, 'privacy' => $arrPriv));
} catch(FacebookApiException $e) {
echo '<div id="text">Error :</div><br /><p style="width: 365px;margin: 0 auto;">Problem authenticating via Facebook, please allow us to share on your behalf.</p>';
echo '<center><a href="https://www.facebook.com/dialog/oauth?client_id=<my_id>&redirect_uri=http://<mysite>/getFacebookData.php&display=popup&scope=email,publish_stream&type=web_server">Allow here</a><center>';
//Send email to admin
$subject = "ERROR Facebook";
$body = "user email:" . $user_email . '| error:' . $e -> getMessage().'|'.$e->getType();
}
編輯: 我發現,當我允許的權限再次(通過收到錯誤消息後鏈接),只有「大家」 /公共生成錯誤,而只有我和朋友不會。
更新(@Axel Amthor):
$facebook = new Facebook(array('appId' => 'app_id', 'secret' => 'removed',));
//We got after the authentication request
$access_token = $_POST['access_token'];
$facebook -> setAccessToken($access_token);
try {
$user_info = $facebook -> api('/me');
$user_id = $user_info['id'];
} catch (FacebookApiException $e) {
//return 0;
}
更新2: 範圍相關的代碼:
$red_url = 'https://www.facebook.com/dialog/oauth?client_id=my_id&redirect_uri=http://mysite/facebook/getFacebookData.php&display=popup&scope=email,publish_stream&type=web_server';
它重定向到getFacebookData.php:
$access_token = '';
$token_url = "https://graph.facebook.com/oauth/access_token?client_id=my_id&redirect_uri=http://mysite/facebook/getFacebookData.php&client_secret=secret&code=" . $_GET['code'];
$access_token = file_get_contents($token_url);
$access_token = substr($access_token, 13, strlen($access_token) - (13 + 16));
它將訪問令牌發送到tird頁面(更新代碼:「更新(@Axel Amthor):」)。
你能粘貼'$ facebook'被實例化和初始化的代碼嗎? –
@AxelAmthor我更新了代碼。 – funerr
你可以驗證這個'$ user_info = $ facebook - > api('/ me');'在工作嗎? –