我正在構建將流發佈到頁面牆上的控制檯應用程序。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
}
這不是錯誤,因爲任何的Facebook應用程序必須第一次被用戶接受,允許該應用程序在他/她的頁面上發佈內容?我知道你不希望用戶必須點擊,但用戶必須第一時間接受。 – Tipx 2011-06-02 15:08:13
@Tipx,感謝您的評論。你知道用戶如何接受facebook應用嗎? – 2011-06-02 15:39:18
http://stackoverflow.com/questions/4743896/fbconnect-the-user-hasnt-authorized-the-application-to-perform-this-action的可能重複。 – Tipx 2011-06-02 15:10:00