0

我照片上傳到Facebook頁面相冊使用以下網址Facebook的照片上傳到網頁相冊

<form id ="uploadForm" method="post" enctype="multipart/form-data"> 
     <h4>UPLOAD PHOTO</h4> 

     <fieldset> 
     <input id="name" type="text" /> 
     </fieldset> 
     <fieldset> 
     <textarea id="photoDtls"></textarea> 
     </fieldset> 
     <fieldset> 
     <input name ="source" type="file" /> 
     </fieldset> 
     <input type="submit"> 
     </form> 

而且我用下面的JavaScript SDK代碼

FB.getLoginStatus(function(response) { 
      if (response.status === 'connected') { 
       accessToken = response.authResponse.accessToken; 
        $('#uploadForm').attr('action','https://graph.facebook.com/photos/*page_album_id*?access_token='+accessToken); 
       }); 
      } else if (response.status === 'not_authorized') { 
       alert('not autherized'); 
       FB.login(function(response){ 
       alert('Permission granted');     
       },{scope: 'email,user_birthday,publish_stream,photo_upload'}); 
      } else { 
       alert('not logged in'); 
      // the user isn't logged in to Facebook. 
      } 
     }); 

我得到的迴應時,我上傳該照片,但我沒有看到照片上傳到我的相冊。有沒有辦法通過以下ID或ID後檢查照片?這裏可能出了什麼問題?

{ 

    "id": "xxxxxxxxxxxxxxxxxxxxx", 
    "post_id": "xxxxxxxx_xxxxxxxxxxxxx" 

} 
+0

當您訪問Facebook上的id或post_id時,您會看到什麼?像www.facebook.com/ - 有你的照片嗎? – Jurik

+0

https://graph.facebook.com/_post-id_給我'{ 「錯誤」:{ 「消息」: 「不支持GET請求。」 「類型」: 「GraphMethodException」, 「代碼」: 100 } }' –

+0

你使用這個例子:https://developers.facebook.com/blog/post/498/?我有一個類似的問題,但它與PHP - 因爲我需要將圖片保存在服務器上,以及:http://stackoverflow.com/questions/7340949/is-it-possible-to-upload-a-photo-沒有發佈 - 它有圖像'圖像'而不是'源'的名字。 – Jurik

回答

1

要將照片上傳到fanpage,您需要使用fanpage令牌而不是用戶令牌。

要獲得此令牌,您需要授予manage_pages權限 - 沒有別的。然後,您將獲得fanpage標記並將其保存在服務器上的某個位置,因爲這需要將照片上傳到粉絲頁面。

這意味着你不能用javascript來做到這一點。因爲那麼每個人都會看到你的fanpage訪問令牌。

因此,您必須將照片發送到您的網絡服務器,然後將其上傳到您的fanpage專輯。

+0

你是對的。但是當我使用應用程序訪問令牌作爲access_token時,我得到一個錯誤消息'用戶訪問令牌需要請求這個資源'我已經要求'scope:'email,user_birthday,publish_stream,photo_upload'}'與應用連接時 –

+1

我更新了答案。後來當我在家時,我也可以發佈一個例子 - 因爲我在Facebook上有一個正在運行的應用程序,作爲頁面標籤,它完全符合你的需求。但它破壞atm,因爲我改變了我的密碼,但沒有更新我的訪問令牌;)https://www.facebook.com/PowerPhotoUploader/app_300214813374674 – Jurik

+0

http://stackoverflow.com/questions/20490801/how-to -get-photos-uploaded-via-facebook-application你對這個有什麼想法嗎? manage_pages只允許管理員用戶上傳到他們的頁面 –