不知道如何使用Facebook c#sdk获取访问令牌 [英] Can't figure out how to get access token using facebook c# sdk

查看:161
本文介绍了不知道如何使用Facebook c#sdk获取访问令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在撰写一个在页面标签中运行的Facebook应用程序。在C#中,我将其作为一个简单的Web Forms应用程序编写,使用从NuGet提取的最新版本的C#SDK。主页标签工作正常。我从FacebookWebContext.Current.SignedRequest获取所需的所有信息,我很好。我正在尝试写一个页面,管理员将使用该页面来设置应用程序,所以这是在应用程序设置中的编辑URL下的页面。

I'm currently writing a Facebook app that runs in a page tab. I'm writing it as a simple Web Forms app in C#, using the latest version of the C# SDK pulled from NuGet. The main page tab works fine. I get all the info I need from FacebookWebContext.Current.SignedRequest, and I'm fine there. I'm trying to write a page now that the page admin would use to set up the app, so this is the page that would go under the "Edit URL" in the app setup.

我真的想做的是获取当前登录的用户ID,并确定他是否是该页面的管理员。

All I really want to do is get the currently signed-on user's ID, and determine if he's an admin for the page in question.

这样做:

var client = new FacebookClient();
dynamic me = client.Get("me");

在Page_Load中,并获得以下异常:

in Page_Load, and getting the following exception:

(OAuthException) An active access token must be used to query information about the current user.

我已经尝试了一堆东西来获取访问令牌,但我似乎不知道我做错了什么有没有一个直接的方法?

I've tried a bunch of stuff to get the access token, but I don't seem to know what I'm doing wrong. Is there a straightforward way of doing this?

更新:
我想到了一点,我参考了旧的JS SDK在我的主页上,这是一个问题。 (见此处)。通过可以查看用户是否真的登录到Facebook,这样可以让我进入我的位置。

Update: I figured out at one point that I had a reference to the old JS SDK on my master page, and that was causing a problem. (See here). Removing that got me to the point where I was usually able to see whether or not the user was actually logged in to Facebook.

推荐答案

尝试这样:

var fbContext = FacebookWebContext.Current;
if (fbContext.IsAuthenticated())
{
    var client = new FacebookClient(fbContext.AccessToken);
    dynamic me = client.Get("me");
}

这篇关于不知道如何使用Facebook c#sdk获取访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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