Post to application wall as application not as user

╄→гoц情女王★ 提交于 2020-01-12 02:22:49

问题


I created an asp.net mvc 3 facebook application using facebook c# sdk.

I'm trying to post to my application wall, it works, but the post is created in this format:

[my account name] via [my application]

So, the post appears in the [my application] + others group.

I want the post appears as made by the application, not made by me, so the post appears in the just [my application] group.

I was looking for answers for this problem, and everybody says, you have to get the access token for application, but nobody says how to do that.

Please could anyone provide an example code of how to do that???


I tried both ways (three really) but all the three gave me the following error:

The entity (class EntApplication) backed by id 204182346262383 cannot be seen by the current viewer 204182346262383 (EntID: 204182346262383).

Here is my code:

    private void Publish(string message, string caption, string description, string name, string picture, string link)
    {
        var args = new Dictionary<string, object>();
        args["message"] = message;
        args["caption"] = caption;
        args["description"] = description;
        args["name"] = name;
        args["picture"] = picture;
        args["link"] = link;

        string path = AppId + "/feed";
        var fbApp = new FacebookClient(GetAppAccessToken());
        fbApp.Post(path, args);
    }

    private string GetAppAccessToken()
    {
        var fb = new FacebookOAuthClient { ClientId = AppId, ClientSecret = SecretKey };
        dynamic result = fb.GetApplicationAccessToken();
        var appAccessToken = result.access_token;
        return appAccessToken.ToString();
    }

I really appreciate help with this, I'm stucked with this for many days. I always get to a dead end.


回答1:


You will need to make the request using facebook application access token.

var fb = new FacebookClient("{app_access_token}");
dynamic result = fb.Post("/{app_id}/feed", new Dictionary<string, object> { { "message", "hello" } });

There are two ways you can use the application token.

  1. Using FacebookOAuthClient: (This method gets the application access token using the OAuth2 standards which is the preferable way to get the app access token. but makes a request to the facebook server.)

    var fb = new FacebookOAuthClient { ClientId = "{app_id}", ClientSecret = "{app_secret}" };
    dynamic result = fb.GetApplicationAccessToken();
    var appAccessToken = result.access_token;
    
  2. Manually creating the application token:

    var appAccessToken = "{app_id}|{app_secret}";
    

Replace {app_id} and {app_secret} with appropriate values.




回答2:


As prabir suggested you need to use a facebook client authenticated as the application and not the connected user.

Here is a short code snipet using version 5.03 beta:

var fbApp = new FacebookClient(FacebookContext.Current);
dynamic result = fbApp.Post("/"+FacebookContext.Current.AppId+"/feed", new Dictionary<string, object> { { "message", "Hello World" } });


来源:https://stackoverflow.com/questions/5053490/post-to-application-wall-as-application-not-as-user

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!