1

実行時に結果を Facebook ページに投稿する Windows サービスを作成しようとしています。

Facebook C# SDK v6.0.10.0 をダウンロードし、.Net 4.0 で Windows アプリケーションを作成しました。

Facebook アプリケーション アカウントを作成し、必要な AppID とシークレット コードを取得しました。

最終的な目標は、この Windows サービスを、アプリケーション ユーザーではなくページとして Facebook ページ ウォールに投稿することです。

Facebook アプリケーションのアカウントを取得しようとすると、エラーが発生し続けます。

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.
    }
}

私が得ているエラーは次の行にあります:

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

(OAuthException - #2500) 現在のユーザーに関する情報を照会するには、アクティブなアクセス トークンを使用する必要があります。

4

2 に答える 2

1

ここを参照してください:(OAuthException-#2500)現在のユーザーに関する情報を照会するには、アクティブなアクセストークンを使用する必要があります

ユーザーではなく、アプリケーションのアクセストークンを取得しています。したがって、「私」は意味がありません。そこでIDを指定する必要があります。ユーザーID、アプリID、またはアプリがアクセス許可を持っているその他のIDのいずれかです。

于 2012-04-20T12:44:18.393 に答える
0
dynamic ac = fbClient.Get("oauth/access_token", new
{
    client_id = strAppID,
    client_secret = strSecret,
    grant_type = "client_credentials"
});

上記のコードはバージョン6.0では機能しない場合があります。

OAuth2.0-アクセストークンのコードを交換する

FacebookClientは、json応答のみの解析をサポートしています。このため、FacebookClient.Get( "oauth / access_token")を使用すると、「oauth/access_token」トークンは機能しません。代わりに、FacebookOAuthClientのメソッドを使用する必要があります。

詳細については、http: //blog.prabir.me/post/Facebook-CSharp-SDK-Making-Requests.aspxをご覧ください。

お役に立てれば。

于 2012-04-24T18:18:05.147 に答える