Facebook从Windows Forms扩展用户访问令牌

时间:2014-12-19 08:54:29

标签: c# facebook

我在Windows窗体应用中有简单的方法,可以在我管理的页面上发布视频。但GRAPH API USER TOKEN已过期。我怎么能延长2天以上? (app将使用2天)

        var fb = new FacebookClient("GRAPH API USER TOKEN");

        dynamic x = fb.Get("/me/accounts", null);

        foreach (var item in x.data)
        {
            if (item.id == "PAGEID")
                fb = new FacebookClient(item.access_token);
        }

        dynamic parameters = new ExpandoObject();
        parameters.source = new FacebookMediaObject { ContentType = "video/mp4", FileName = VideoId + ".mp4" }.SetValue(File.ReadAllBytes(@"c:\x\y\" + VideoId + ".mp4"));
        parameters.title = "foo";
        parameters.description = "more foo";

        dynamic result = fb.Post("/PAGEID/videos", parameters);

1 个答案:

答案 0 :(得分:0)

您需要将该短期令牌换成扩展令牌。

可以通过以下调用完成:

https://graph.facebook.com/oauth/access_token?             
client_id=APP_ID&
client_secret=APP_SECRET&
grant_type=fb_exchange_token&
fb_exchange_token=EXISTING_ACCESS_TOKEN 

您的扩展令牌位于回复中。

使用C#SDK:

var  result = _fb.Post("oauth/access_token",
              new
              {
                 client_id = "APP_ID",
                 client_secret = "APP_SECRET",
                  grant_type = "fb_exchange_token",
                  fb_exchange_token= "SHORT_LIVED_TOKEN"
               });