2012-02-23 113 views
1

Facebook頁面牆我試圖張貼到使用捲曲我的Facebook頁面牆上,但我不斷收到以下錯誤發佈通過捲曲

The user hasn't authorized the application to perform this action 

如何生成使用curl正確的訪問令牌?如果你去這個網址http://developers.facebook.com/tools/explorer/

然後我可以把下面的https://graph.facebook.com/337588736279406/feed,這將顯示出我的牆飼料的話,我可以改變這個發佈和添加一個字段的信息內容,如果我再運行此我得到以下響應。

{ 
    "error": { 
    "message": "(#200) The user hasn't authorised the application to perform this action", 
    "type": "OAuthException", 
    "code": 200 
    } 
} 

我必須做什麼來授權我作爲用戶?

有人可以幫助我做到這一點。

<?php 

function postify($arr) { 
    $fields_string = ''; 
    foreach ($arr as $key => $value) { 
     $fields_string .= $key . '=' . $value . '&'; 
    } 
    return rtrim($fields_string, '&'); 
} 


$appid = 'app id'; 
$redirect_url = 'http://stickynote.users36.interdns.co.uk'; 
$app_secret = 'app secret'; 
$page_id = '337588736279406'; 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id='.$appid.'&redirect_uri='.$redirect_url.'&client_secret='.$app_secret.'&perms=publish_stream'); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$output = curl_exec($ch); 

$output = explode("=", $output); 

curl_close($ch); 

$postdata = array(
    'message' => 'this is a test message', 
); 


$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/'.$page_id.'/feed?access_token='.$output[1].''); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, postify($postdata)); 
$check = curl_exec($ch); 

print_r($check);   

?> 

回答

1

爲了能夠發佈內容,您必須將publish_stream權限授予您的應用程序。

請求權限可以使用OAuth Dialog完成。

順便說一句,如果您只是爲了測試目的需要用戶,您可以通過選擇您的應用程序使用Explorer Tool,點擊獲取訪問令牌並檢查所需的權限。

更新:
您將無法張貼代表的應用程序,只有用戶或頁面適當access_token的(對於網頁時,需要manage_pagesaccess_tokenuseraccounts連接)。 不需要在access_token檢索URL中指定perms。應該在該步驟之前授予權限。

+0

我該如何做到這一點可以幫助 – DCHP 2012-02-23 16:40:21

+0

我已經發布了我的完整代碼 – DCHP 2012-02-23 16:43:12

+0

嗨多汁感謝回覆我很高興困惑我如何通過捲髮返回訪問令牌我可以運行你說的http:// www。 facebook.com/dialog/oauth/?scope=email,user_birthday,publish_stream&client_id=277938122277013&redirect_uri=http://stickynote.users36.interdns.co.uk&response_type=token這會返回我的url中的代碼,然後我如何訪問這通過curl – DCHP 2012-02-23 16:54:53

0

你需要獲得一個頁面訪問令牌來做到這一點。

在它說documentation

頁的access_token

用來管理一個頁面的的access_token。當你想執行一個充當頁面的操作時,這被用於 。此訪問 令牌通過使用manage_pages權限發出HTTP GET到/ USER_ID/accounts或 /PAGE_ID?fields = access_token來檢索。獲取 /USER_ID /帳戶將返回除每個網頁的 access_token之外用戶具有管理訪問權限的頁面列表(包括應用程序配置文件 頁面)。或者,通過使用manage_pages權限發出HTTP GET到 /PAGE_ID?fields = access_token(您的 必須特別通過字段= 參數請求access_token字段),才能獲得單個特定頁面的頁面訪問令牌 )。請參閱Page對象的文檔以瞭解更多信息 信息

獲得訪問令牌後,您可以進行這些api調用。

+0

1.你只需要這個,如果你想發佈爲它的頁面f,它不需要作爲用戶發佈。 2.您需要申請'publish_stream'才能發佈內容。 – 2012-02-23 16:35:39