Facebook的C#SDK麻烦我/账户 [英] Facebook C# SDK trouble getting me/accounts

查看:254
本文介绍了Facebook的C#SDK麻烦我/账户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个窗口服务,将张贴到我的Facebook页面与结果在运行时。



我刚刚下载的Facebook C#SDK v6.0.10。 0在.NET 4.0编写Windows应用程序



我创建了一个Facebook应用程序的帐户,并得到了的AppID和秘密代码所需。



最终的目标将是在我的Facebook页面墙上的页面,而不是应用程序的用户这个窗口服务岗位。



我不断收到一个错误。当我去为我的Facebook应用程序的帐户

 字符串strAppID =我的应用程序的API ID 
串strSecret =我的应用程序密码;
Facebook.FacebookClient fbClient =新Facebook.FacebookClient();
fbClient.AppId = strAppID;
fbClient.AppSecret = strSecret;
动态AC = fbClient.Get(OAuth的/的access_token,新的
{
CLIENT_ID = strAppID,
client_secret = strSecret,
grant_type =client_credentials
});

串strAccessToken =的String.Empty;
strAccessToken = ac.access_token;
如果
{

fbClient =新Facebook.FacebookClient(strAccessToken)(String.IsNullOrEmpty(strAccessToken)!);
fbClient.AccessToken = strAccessToken;
fbClient.AppId = strAppID;
fbClient.AppSecret = strSecret;

//这里是被轰炸
动态fbAccounts = fbClient.Get(/ ME /账户);

fbClient =新Facebook.FacebookClient(strAccessToken);
fbClient.AccessToken = strAccessToken;
fbClient.AppId = strAppID;
fbClient.AppSecret = strSecret;

动力箱= fbClient.Get(** Facebook页面我试图张贴到**的名称);

串strPageID =的String.Empty;
strPageID = me.id;

串strPageAccessToken =的String.Empty;

//循环寻找你的目的地ID(粉丝专页ID)
的foreach(在fbAccounts.data动态账户)
匹配的ID账户{
如果(account.id == strPageID)
{
//当你找到它,抓住相关的访问令牌,并把它在字典中的FB邮通,然后爆发。
strPageAccessToken = account.access_token;
中断;
}
}



{
fbClient.AccessToken = strPageAccessToken;
变参=新词典<字符串对象>();
ARGS [消息] =测试123;
fbClient.Post(/+ strPageID +/饲料,参数);

}
赶上(Facebook.FacebookOAuthException前)
{
// OAuth的异常出现
}
赶上(Facebook.FacebookApiLimitException前)
{
// API限制例外发生。
}
赶上(Facebook.FacebookApiException前)
{
//其他一般的Facebook API例外
}
赶上(异常前)
{
//非Facebook的异常,如没有互联网连接。
}
}



我正的错误就行了:

 动态fbAccounts = fbClient.Get(/ ME /账户); 



(OAuthException - #2500)有效的访问令牌,必须使用查询有关当前用户的信息。


解决方案

在这里看到:的(OAuthException - #2500)有效的访问令牌,必须使用查询有关当前用户


你正在访问令牌对于应用程序,而不是用户。
所以,我是没有意义的。你应该有提供ID -
或者您的用户ID,或者您的应用程序ID或任何其他ID您的应用程序有
权限



I'm trying to write a windows service that will post to my Facebook Page with results when it runs.

I just downloaded Facebook C# SDK v6.0.10.0 and writing the windows application in .Net 4.0

I created a facebook application account and got the AppID and Secret code needed.

The end goal would be to have this windows service post on my facebook page wall as the page and not the application user.

I keep getting an error when I go to get the accounts for my facebook application.

string strAppID = "my app api id";
string strSecret = "my app secret code";
Facebook.FacebookClient fbClient = new Facebook.FacebookClient();
fbClient.AppId = strAppID;
fbClient.AppSecret = strSecret;
dynamic ac = fbClient.Get("oauth/access_token", new
{
    client_id = strAppID,
    client_secret = strSecret,
    grant_type = "client_credentials"
});

string strAccessToken = String.Empty;
strAccessToken = ac.access_token;
if (!String.IsNullOrEmpty(strAccessToken))
{

    fbClient = new Facebook.FacebookClient(strAccessToken);
    fbClient.AccessToken = strAccessToken;
    fbClient.AppId = strAppID;
    fbClient.AppSecret = strSecret;

    //Here is where it is bombing
    dynamic fbAccounts = fbClient.Get("/me/accounts");

    fbClient = new Facebook.FacebookClient(strAccessToken);
    fbClient.AccessToken = strAccessToken;
    fbClient.AppId = strAppID;
    fbClient.AppSecret = strSecret;

    dynamic me = fbClient.Get("**Name of the facebook page I am trying to post to**");

    string strPageID = String.Empty;
    strPageID = me.id;

    string strPageAccessToken = String.Empty;

    //Loop over the accounts looking for the ID that matches your destination ID (Fan Page ID)
    foreach (dynamic account in fbAccounts.data)
    {
        if (account.id == strPageID)
        {
            //When you find it, grab the associated access token and put it in the Dictionary to pass in the FB Post, then break out.
            strPageAccessToken = account.access_token;
            break;
        }
    }


    try
    {
        fbClient.AccessToken = strPageAccessToken;
        var args = new Dictionary<string, object>();
        args["message"] = "Testing 123";
        fbClient.Post("/" + strPageID + "/feed", args);

    }
    catch (Facebook.FacebookOAuthException ex)
    {
        // oauth exception occurred
    }
    catch (Facebook.FacebookApiLimitException ex)
    {
        // api limit exception occurred.
    }
    catch (Facebook.FacebookApiException ex)
    {
        // other general facebook api exception
    }
    catch (Exception ex)
    {
        // non-facebook exception such as no internet connection.
    }
}

The error I am getting is on the line:

dynamic fbAccounts = fbClient.Get("/me/accounts");

(OAuthException - #2500) An active access token must be used to query information about the current user.

解决方案

see here: (OAuthException - #2500) An active access token must be used to query information about the current user

you are getting access token for the APPLICATION, not for a user. Therefore, "me" does not make sense. You should supply ID there - either your user ID, or your app ID, or any other ID your app has permissions for.

这篇关于Facebook的C#SDK麻烦我/账户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆