2012-02-13 42 views
3

我無法使用權​​限上傳到特定的Facebook專輯。將圖像上傳到特定的Facebook專輯

我設置爲特定Facebook頁面的管理員,但每當我嘗試上傳照片時,我似乎都無法訪問它。

我得到的錯誤是:

Fatal error: Uncaught OAuthException: (#120) Invalid album id thrown

如果我探討使用圖形瀏覽器中,我可以看到這張專輯,而不需要任何訪問令牌。

我使用的URL是https://graph.facebook.com/albumId/photos

我要上傳這張專輯是一個Facebook頁面內的專輯,這是我在Facebook創建的。

我設置的權限包括:

  • user_photos
  • friends_photos
  • publish_actions
  • manage_pages
  • publish_stream
  • photo_upload

任何幫助表示讚賞。

回答

1

首先,檢查如果用戶登錄:

function getLoginStatus() { 
      FB.getLoginStatus(function (response) { 
       if (response.status === 'connected') { 
        // the user is logged in and connected to your 
        // app, and response.authResponse supplies 
        // the user's ID, a valid access token, a signed 
        // request, and the time the access token 
        // and signed request each expire 
        var uid = response.authResponse.userID; 
        var accessToken = response.authResponse.accessToken; 

        getPageAccess(); 

       } else if (response.status === 'not_authorized') { 
        // the user is logged in to Facebook, 
        //but not connected to the app 
        logIn(); 
       } else { 
        // the user isn't even logged in to Facebook. 
        logIn(); 
       } 
      }); 
     } 

然後獲得與用戶關聯的頁面訪問令牌:

function getPageAccess() {    
      FB.api('/PAGE_ID?fields=access_token', function (resp) { 
       var pageAccessToken = resp.access_token; 
      }); 
     } 
0

好的,我想我找到了解決方案。

如果你去https://graph.facebook.com/me/accounts

每個帳戶將擁有自己的access_token。將圖像上傳到Facebook頁面時,您需要將該access_token作爲參數傳遞。

1

這似乎是一個常見的問題。如果您想模仿Facebook頁面(即充當頁面本身的上傳,發佈和共享),您必須先獲得該頁面的訪問令牌:

  1. 發出GET請求以「/ me/accounts 「使用令牌
  2. 循環的結果集,並查找網頁的用戶訪問(注意每個項目的類別屬性,跳過‘應用程序’,因爲它是考慮一個帳戶)
  3. 商店access token該頁面。

然後(使用PHP SDK):

$page = '432652662'; // Your page id 
$album = '128949205'; // Your album id 
$source = 'mypic.png'; 
$payload = array('source' => '@' . $source, 
    'access_token' => 'page access token'); 

// Upload photo for specific page and album 
$sdk->api("/$page/$album/photos", 'POST', $payload); 
相關問題