Skip to content

Instantly share code, notes, and snippets.

@Godoy
Last active December 15, 2015 20:49
Show Gist options
  • Select an option

  • Save Godoy/5321512 to your computer and use it in GitHub Desktop.

Select an option

Save Godoy/5321512 to your computer and use it in GitHub Desktop.
Obter access_token do facebook após o callback de login usando a lib Facebook C# SDK (https://github.com/facebook-csharp-sdk/facebook-csharp-sdk/)
@{
string permalink = Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath + "/MeuController/actionCallback/";
string appId = "9999990999";
}
<!--Login Oauth-->
<p><a href="https://www.facebook.com/dialog/oauth/?client_id=@appId&redirect_uri=@permalink&scope=photo_upload&display=page&state=logged" >Login</a></p>
using Facebook;
....
public ActionResult actionCallback()
{
try
{
if (String.IsNullOrEmpty(Request["code"]))
throw new Exception("Não foi possível efetuar login na aplicação.");
dynamic result = fb.Get("oauth/access_token", new
{
client_id = "279271518842322",
client_secret = "e58e3f943cb8e81afdd1ed8252f442cf",
code = Request["code"],
redirect_uri = Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath + "/MeuController/actionCallback/"
});
fb.AccessToken = result.access_token;
Session["FbAcessToken"] = (string)result.access_token;
}
catch(Exception e)
{
ViewBag.Msg = e.Message.ToString();
//ViewBag.Msg = "Ocorreu um erro ao compartilhar a imagem.";
return View();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment