开发者

Facebook User Authentication in C#/WPF?

I am new to Facebook app development and have stumbled across a road block. After reading the documentation, I sort of understand that the process of using Facebook login is done in there steps: user开发者_开发知识库 authentication -> app authorization -> app authentication. I see where the app authroization/authentication is done, but I can't seem to figure out how to bring up a "user login" screen of Facebook on my WPF. Can anyone advise? Thanks!


First of all you need to register a application in Facebook. Don't forget to give a canvas url when registering an application. After registration you should get app id and app secret values.

https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=YOUR_URL
  • YOUR_APP_ID means your application id
  • YOUR_URL means that application canvas url.

Wpf has a web browser control, you just call the Navigate function and give this url. You should get a Facebook login dialog.

After giving the correct user id and password, Facebook should popup a permission dialog then click the Allow button , you should get a code with redirect url. Then you should parse the code from this url and create a web request to get an access token:

https://graph.facebook.com/oauth/access_token?client_id=YOUR_APP_ID&redirect_uri=YOUR_URL& client_secret=YOUR_APP_SECRET&code=THE_CODE_FROM_ABOVE

  • YOUR_APP_ID is application id
  • YOUR_URL is application redirect url
  • YOUR_APP_SECRET means application secret
  • THE_CODE_FROM_ABOVE code get from above.

After executing this request, you should get an access token. Using this token you can access Facebook functionality from your application.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜