简体   繁体   中英

Still no solution how to simple post a Facebook wall

I need to post a message from my personal website to the website´s facebook wall page. I dont want the user to authenticate against facebook , instead a default website account should be used(probably the facebook app).

This is what I have :

  1. Created facebook App at https://developers.facebook.com
  2. Add Facebook.dll to my ASP.NET webform site(the personal site)
  3. Included the following code :

    FacebookClient client = new FacebookClient();

     result = client.Get("oauth/access_token", new { client_id = ConfigurationManager.AppSettings["FacebookAppId"], client_secret = ConfigurationManager.AppSettings["FacebookAppSecret"], grant_type = "client_credentials" }); client.AccessToken = result.access_token; result = client.Post("1418771281723422/feed", new { message = "Test Message from app" }); result = client.Get("1418771281723422"); 

This returns the following exception on client.Post

A first chance exception of type 'Facebook.FacebookOAuthException' occurred in Facebook.dll

Additional information: (OAuthException - #200) (#200) The user hasn't authorized the application to perform this action

What am I doing wrong and why is it so hard to do this simple task?

Of course you need to authorize a User to post on Facebook - else it would be incredibly easy to create a spam App.

What you need is a Page Access Token, take a look at the Facebook docs about the different Tokens and how to get them: https://developers.facebook.com/docs/facebook-login/access-tokens

More information about Access Tokens: http://www.devils-heaven.com/facebook-access-tokens/

The code is in PHP, but the text is valid for every language anyway.

This is how to generate an Extended Page Token with PHP: http://www.devils-heaven.com/extended-page-access-tokens-curl/

An Extended Page Token may be exactly what you need, it is valid forever and you can post "as Page" with it.

Doing this with ASP.NET should be pretty similar, but you don´t really need that Facebook SDK if you take a look at the tutorial for extending a Page Token with CURL. This question may help you: curl Request with ASP.NET

To create an Extended Page Token only for yourself, i suggest creating it without any coding:

It´s explained in this article: http://www.devils-heaven.com/facebook-access-tokens/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM