2016-11-04 105 views
1

我正在使用FB應用程序發佈帖子到我的FB頁面。 所以,當我使用這段代碼的鏈接,它的作品。Facebook圖:張貼圖片不是用戶

$facebook = new Facebook(array(
'appId' => $fb_app_id, 
'secret' => $fb_secret, 
'cookie' => true 
)); 

$attachment = array(
     'access_token' => $row["token"], 
     'name' => $_POST["name"], 
     'picture' => $_POST["picture"], 
     'message' => $_POST["message"], 
     'link' => $_POST["link"]); 
    try 
    { 
     $facebook->api("/".$row['id']."/feed", "POST", $attachment); 
    } 

    catch(Exception $e) 
    { 
     echo('exception caught '.$e->getMessage()); 
    } 

但是,當我想分享的圖片作爲頁面:

$facebook = new Facebook(array(
    'appId' => $fb_app_id, 
    'secret' => $fb_secret, 
    'cookie' => true, 
    'fileUpload' => true, 
    'allowSignedRequest' => false 
    )); 

$attachment = array('access_token' => $row["token"], 'url' => 'http://image.link.jpg', 'message' => $_POST["message"]); 
      try 
      { 
       $facebook->api("/".$row['id']."/photos", "POST", $attachment); 
      } 
      catch(Exception $e) 
      { 
       echo('exception caught '.$e->getMessage()); 
      } 

該應用程序後的圖片作爲用戶。用戶到頁面。 所以我發現我需要使用publish_pages權限,但我的訪問令牌包含publish_actions和publish_pages。我無法改變這種情況,因爲我使用一個訪問令牌做了很多事情。

enter image description here

所以我要問,有沒有辦法明確選擇我想從訪問令牌使用的權限。 FB API具有相同的頁面和用戶圖片發佈/ user_id/photos和/ page_id/photos的代碼。

+1

您需要使用頁面訪問令牌而不是用戶訪問令牌。 https://developers.facebook.com/docs/facebook-login/access-tokens – CBroe

回答

0

需要使用頁面訪問令牌,沒有其他辦法。