2013-05-22 37 views
0

我希望能夠發佈到用戶牆,(他編輯的消息)。但是,如果用戶沒有讓代表他發佈,然後我得到了以下錯誤: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):」)。

+0

你能粘貼'$ facebook'被實例化和初始化的代碼嗎? –

+0

@AxelAmthor我更新了代碼。 – funerr

+0

你可以驗證這個'$ user_info = $ facebook - > api('/ me');'在工作嗎? –

回答

0

缺少範圍參數類似(從我的代碼):

$OAuth_request = _formatOAuthReq($OAuth, "read_insights,ads_management,publish_actions,manage_pages,publish_stream,read_stream,offline_access", $state); 

.... 

function _formatOAuthReq($OAuthParams, $scope, $state) 
{ 
    $uri = $OAuthParams['oauth_uri']; 
    $uri .= "?client_id=" . $OAuthParams['client_id']; 
    $uri .= "&redirect_uri=" . $OAuthParams['redirect_uri']; 
    $uri .= "&scope=" . $scope; 
    $uri .= "&response_type=code"; 
    $uri .= "&approval_prompt=force&access_type=offline"; 

爲了發佈對用戶的一些個人資料,請考慮以下權限:

  1. create_event
  2. create_note
  3. photo_upload
  4. publish_stream
  5. read_stream
  6. status_update
  7. video_upload
  8. 電子郵件
  9. publish_actions

按照/[acctid]/feed你要發佈由[acctid]標識的用戶牆上的 「音符」。實際上,這是使用OAuth對話框中提供的訪問令牌「登錄」的用戶。我只是捅到我們的代碼在這裏和我們正在做的,與

/me/feed

,這工作就像一個魅力。實際上,你不是在向「外國用戶」發帖,而是由用戶親自發布,並通過授權應用程序代表他/她自行將應用發佈到他/她自己的牆上。我知道,方式複雜。

+0

「/ me/feed」修復了問題!謝謝:)(把重點放在那,所以其他用戶將立即顯示答案)。 – funerr

0

I found that when I allow the permissions again (via the link after getting the error message), only the "everyone"/ public is generating the error, while only-me and friends do not.

所以你要用戶公開發布?你不應該那樣做 - 讓用戶決定!

在應用設置可能設置爲「公開」爲默認操作隱私 - 然後,用戶可以更改爲更嚴格的值,如果他們喜歡直接從登錄對話框或以後在他們的個人資料的應用程序設置。

然後在API調用中完全不給出privacy參數,以便用戶選擇的值自動應用。

+0

我給用戶一個選擇元素,在那裏他可以選擇輸入什麼選項,當他們嘗試選擇公共選項時,它會破壞功能。 另外我已經將「public」設置爲默認值。 – funerr

相關問題