Facebook C# SDK and Access Token

后端 未结 3 1608
长发绾君心
长发绾君心 2020-12-17 15:38

I\'d like to be able to authenticate myself (my profile, not just my app) on my own web application using the Facebook C# SDK. Using the Graph API, I can ge

相关标签:
3条回答
  • 2020-12-17 16:23

    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.

    0 讨论(0)
  • 2020-12-17 16:36

    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 !!

    0 讨论(0)
  • 2020-12-17 16:40

    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.

    0 讨论(0)
提交回复
热议问题