Facebook C# SDK and Access Token

我只是一个虾纸丫 提交于 2019-11-29 05:53:36

When you say "yourself" do you mean the app or your actual facebook user?

If it's just your app, you can get an access token by POSTing to this URL:

https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id=APP_ID_HERE&client_secret=APP_SECRET_HERE

You can use this access token to perform actions on behalf of your users if they have authorized your app to do so.

jimmystormig

I had the same problem where the access token didn't include the session part. Please check out my answer to this similar question - exchange code for token facebook-c#-sdk.

Here's a sample from my Home controller

[CanvasAuthorize]
public ActionResult Index()
{
    var app = new FacebookClient(new Authorizer().Session.AccessToken);

    dynamic me = app.Get("me");
    ViewBag.Firstname = me.first_name;
    ViewBag.Lastname = me.last_name;

    return View();
}

Edit

Now I understand the question better. What about this?

var auth = new Authorizer(FacebookContext.Current.AppId, FacebookContext.Current.AppSecret, HttpContext);

auth.Authorize();

From the documentation:

public bool Authorize() Member of Facebook.Web.Authorizer

Summary: Authorizes the user if the user is not logged in or the application does not have all the sepcified permissions.

Returns: Return true if the user is authenticated and the application has all the specified permissions.

I dont know if this will work for you:

using Facebook.Web;
using Facebook;
using System.Dynamic;

var auth = new CanvasAuthorizer { Permissions = new[] { "user_about_me"} };

if (auth.Authorize())
{
}

and include this in the aspx:

<input type="hidden" name="signed_request" value="<%: Request.Params["signed_request"]%>"/>

good luck !!

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