简体   繁体   English

Facebook API登录C#桌面应用程序

[英]Facebook API Login C# Desktop App

I am trying to simply connect to the Facebook Graph using a C# console app, but am having a FacebookOAuth Exception. 我正在尝试使用C#控制台应用程序简单地连接到Facebook Graph,但是遇到了FacebookOAuth异常。 Here is my code so far: 到目前为止,这是我的代码:

       var client = new FacebookClient();

        // Exchange the code for an access token

        dynamic result = client.Get("/oauth/access_token", new
        {
            client_id = "****************",
            client_secret = "*****************************",
            redirect_uri = "http://www.teamdavix.com",
        });

        // Read the auth values
        string accessToken = result.access_token;

        DateTime expires = DateTime.UtcNow.AddSeconds(Convert.ToDouble(result.expires));

        var query = "SELECT author_uid, page_id, message FROM checkin WHERE page_id = 357981198572";

        dynamic parameters = new ExpandoObject();
        parameters.q = query;
        dynamic results = client.Get("/fql", parameters);
        Console.WriteLine(results);
        Console.ReadKey();

You have to use https://www.facebook.com/connect/login_success.html as the redirect_uri from desktop applications. 您必须使用https://www.facebook.com/connect/login_success.html作为桌面应用程序中的redirect_uri。 The information from a successful login will be passed as url fragments (after a #) in the url. 成功登录的信息将作为URL片段(在#之后)传递。 If there is an error it will be passed as query string parameters (after a ?) in the url. 如果有错误,它将作为查询字符串参数(在?之后)传递到url中。

http://www.hackviking.com/2014/11/facebook-api-login-flow-for-desktop-application/ - complete example how to implement a login flow from a desktop application. http://www.hackviking.com/2014/11/facebook-api-login-flow-for-desktop-application/-完整示例说明如何从桌面应用程序实现登录流程。

https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow/v2.2 - more information about how to build your own login flow. https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow/v2.2-有关如何构建自己的登录流的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM