在单元测试方法中以编程方式获取访问令牌

时间:2014-11-17 22:08:25

标签: c# facebook facebook-c#-sdk facebook-sdk-4.0

首先,我打开Facebook Developers页面,然后创建新的App。 (我得到AppID,AppSecret值)

我想创建单元测试方法来执行发布到墙上以及稍后删除帖子。 publish_stream,publish_actions

手动 ,我这样做了3个步骤

打开网址

https://graph.facebook.com/oauth/authorize?client_id=xxxxx&redirect_uri=http://www.kiquenet.com/&scope=publish_stream,publish_actions

然后,此网址打开,我得到代码值

http://www.kiquenet.com/?code=A....3qhOw#=

然后,打开此网址,我会获得访问令牌值: https://graph.facebook.com/oauth/access_token?client_id=xxxxx&redirect_uri=http://www.kiquenet.com/&scope=publish_stream,publish_actions&client_secret=zzzzz&code=A...3qhOw#=

最后,我获得了访问令牌:

  const string token = "C...SNo";

我的代码现在用于我的单元测试工作。只有我需要删除。

using Facebook;
        [TestMethod]
        public void Post_to_the_wall()
        {

            var client = new FacebookClient(token);
            dynamic parameters = new ExpandoObject();
            parameters.message = "Check out this funny article";
            parameters.link = "http://www.example.com/article.html";
            parameters.picture = "http://www.example.com/article-thumbnail.jpg";
            parameters.name = "Article Title";
            parameters.caption = "Caption for the link";
            parameters.description = "Longer description of the link";
            parameters.actions = new
            {
                name = "View on Zombo",
                link = "http://www.zombo.com",
            };
            parameters.privacy = new
            {
                value = "ALL_FRIENDS",
            };

            dynamic result = client.Post("me/feed", parameters);

           // TODO: NOW, delete the post ???
        }

如何以编程方式执行3 手动 步骤?

0 个答案:

没有答案