Facebook C# SDK Mühe, mir/Konten

Ich versuche zu schreiben, ein windows-Dienst, der post wird zu meiner Facebook Seite mit den Ergebnissen, wenn es läuft.

Ich habe gerade heruntergeladen Facebook C# SDK v6.0.10.0 und schreiben der windows-Anwendung .Net 4.0

Erstellte ich eine facebook-Anwendung-Konto und bekam die AppID und Secret code, der benötigt wird.

Ende Ziel wäre es, dieses windows-service-Beitrag auf meiner facebook Seite an der Wand, wie die Seite und nicht den Benutzer der Anwendung.

Ich erhalte eine Fehlermeldung, wenn ich gehen, um die Konten für meine facebook-Anwendung.

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

Den Fehler bin ich immer auf der Linie:

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

(OAuthException - #2500) Einen aktiven access token muss verwendet werden, zur Abfrage von Informationen über den aktuellen Benutzer.

InformationsquelleAutor Shaun D | 2012-04-19

Schreibe einen Kommentar