以应用程序身份而不是用户身份发布到应用程序墙 [英] Post to application wall as application not as user

查看:58
本文介绍了以应用程序身份而不是用户身份发布到应用程序墙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用facebook c#sdk创建了一个 asp.net mvc 3 facebook应用程序.

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:

[我的帐户名]通过[我的应用程序]

因此,该帖子显示在 [我的应用程序] +其他组中.

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:

当前查看器204182346262383(EntID:204182346262383)无法看到由id 204182346262383支持的实体(EntApplication类).

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

这是我的代码:

    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.

推荐答案

您将需要使用Facebook应用程序访问令牌进行请求.

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. 使用FacebookOAuthClient :(此方法使用OAuth2标准获取应用程序访问令牌,这是获取应用程序访问令牌的首选方法,但会向Facebook服务器发出请求.)

  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;

  • 手动创建应用程序令牌:

  • Manually creating the application token:

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

  • 用适当的值替换{app_id}和{app_secret}.

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

    这篇关于以应用程序身份而不是用户身份发布到应用程序墙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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