2011-06-02 100 views
0

我正在構建將流發佈到頁面牆上的控制檯應用程序。facebook c#sdk - 用戶尚未授權應用程序執行此操作

問題:我得到「用戶未授權應用程序執行此操作」。我使用opengraph來獲取訪問令牌。

我錯過了什麼嗎?任何幫助是極大的讚賞。謝謝!

// constants 
string apiKey = "XXX"; 
string secret = "XXX"; 
string pageId = "XXX"; 

// get access token 
string url = string.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&client_secret={1}&grant_type=client_credentials", apiKey, secret); // todo: figure out open graph url 
WebRequest req = WebRequest.Create(url); 
WebResponse resp = req.GetResponse(); 
StreamReader reader = new StreamReader(resp.GetResponseStream()); 
string respStr = reader.ReadToEnd(); 
string accessToken = respStr.Replace("access_token=", ""); 

// construct the post 
dynamic messagePost = new ExpandoObject(); 
messagePost.access_token = accessToken; 
messagePost.picture = "www.google.com/pic.png"; 
messagePost.link = "www.google.com"; 
messagePost.name = "some name"; 
messagePost.captiion = "some caption"; 
messagePost.description = "some description"; 
messagePost.req_perms = "publish_stream"; 
messagePost.scope = "publish_stream"; 

// using client 
FacebookClient client = new FacebookClient(accessToken); 

try // to post the post to the page's wall 
{ 
    var result = client.Post(string.Format("/{0}/feed", pageId), messagePost); 
} 
    catch (FacebookOAuthException ex) 
{ 
    // getting caught here, with error msg = "The user hasn't authorized the application to perform this action" 
} 
catch (FacebookApiException ex) 
{ 
    // ignore 
} 
+0

這不是錯誤,因爲任何的Facebook應用程序必須第一次被用戶接受,允許該應用程序在他/她的頁面上發佈內容?我知道你不希望用戶必須點擊,但用戶必須第一時間接受。 – Tipx 2011-06-02 15:08:13

+0

@Tipx,感謝您的評論。你知道用戶如何接受facebook應用嗎? – 2011-06-02 15:39:18

+0

http://stackoverflow.com/questions/4743896/fbconnect-the-user-hasnt-authorized-the-application-to-perform-this-action的可能重複。 – Tipx 2011-06-02 15:10:00

回答

1
+0

FWIW,這些天我認爲profile_selector消失了,這使得這個解決方案不再是非常正確的。 (至少,如果有profile_selector的替代品,我還沒有看到它:據稱這些天,據稱這些天(http://stackoverflow.com/questions/8045317/status-of-enable-profile-selector-with-oauth-2) manage_pages是你所需要的,然後你抓取頁面的訪問令牌發佈給它。 – 2012-03-14 09:02:03

0

「喜歡你的應用程序」和「允許你的應用程序貼在他的牆上」是兩個不同的句子。沒有魔術棒可以讓你覆蓋用戶的喜好,不管他們喜歡與否。

最好的辦法是處理「失敗」並轉向下一個人。如果你想知道不想讓你張貼在牆上的同志,你可以在返回時獲取這些信息,並將其存儲在某種「日誌」中。

+0

嗨格雷戈裏,感謝您的評論!我只是更新了描述。我只是看着如何使用facebook c#sdk發佈帖子到頁面的牆上。 – 2011-06-02 15:10:27

相關問題