facebook c#sdk-用户未授权应用程序执行此操作 [英] facebook c# sdk - The user hasn't authorized the application to perform this action
问题描述
我正在构建一个控制台应用程序,该应用程序将流发布到页面的墙上.
I am building a console app that will publish streams to a page's wall.
问题:我收到用户未授权应用程序执行此操作".我正在使用opengraph获取访问令牌.
Issue: I'm getting "The user hasn't authorized the application to perform this action". I'm using opengraph to get the access token.
我错过了什么吗?任何帮助是极大的赞赏.谢谢!
Am I missing something? Any help is greatly appreciated. Thanks!
// 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
}
推荐答案
访问以下链接后,我能够运行代码并将其成功发布到页面的墙上,之后它显示在Likers的新闻中提要.
After visiting the following links, I was able to run the code and have it successfully publish to the page's wall, after which it shows up in the Likers' news feeds.
http://www.facebook.com/login.php?api_key= {API_KEY_GOES_HERE}& next = http://www.facebook .com/connect/login_success.html& req_perms = read_stream,publish_stream
http://www.facebook.com/login.php?api_key={API_KEY_GOES_HERE}&next=http://www.facebook.com/connect/login_success.html&req_perms=read_stream,publish_stream
> http://www.facebook.com/connect/prompt_permissions.php? api_key = {API_KEY_GOES_HERE}& next =
http://www.facebook.com/connect/prompt_permissions.php?api_key={API_KEY_GOES_HERE}&next=http://www.facebook.com/connect/login_success.html?xxRESULTTOKENxx&display=popup&ext_perm=publish_stream&profile_selector_ids={PAGE_ID_GOES_HERE}
这篇关于facebook c#sdk-用户未授权应用程序执行此操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!