【问题标题】:Invalid parameter exception on client.auth_getSession() in Facebook java APIFacebook java API中client.auth_getSession()的参数异常无效
【发布时间】:2009-06-25 04:13:19
【问题描述】:

我想使用 facebook java api 2.1.1(http://code.google.com/p/facebook-java-api/) 连接到我的 facebook 应用程序。我的应用程序处于“桌面”模式,因此我应该能够在 Web 应用程序之外访问它。我也没有为它定义任何回调 url。我的代码看起来像这样。

FacebookJsonRestClient client = new FacebookJsonRestClient( FB_APP_API_KEY, FB_APP_SECRET );
String token = client.auth_createToken();
HttpClient http = new HttpClient();
http.setParams(new HttpClientParams());
http.setState(new HttpState());

final String LOGIN = "https://login.facebook.com/login.php";

GetMethod get = new GetMethod(LOGIN + "?api_key=" + FB_APP_API_KEY + "&v=1.0&auth_token=" + token );

http.executeMethod(get);

PostMethod post = new PostMethod(LOGIN);
post.addParameter(new NameValuePair("api_key", FB_APP_API_KEY));
post.addParameter(new NameValuePair("v", "1.0"));
post.addParameter(new NameValuePair("auth_token", token));
post.addParameter(new NameValuePair("email", "my-email"));
post.addParameter(new NameValuePair("pass", "my-password"));

http.executeMethod(post);

String session = client.auth_getSession(token);

但是,API 不会返回会话,而是抛出异常:

com.google.code.facebookapi.FacebookException: Invalid parameter
    at com.google.code.facebookapi.FacebookJsonRestClient.parseCallResult(FacebookJsonRestClient.java:354)
    at com.google.code.facebookapi.ExtensibleClient.callMethod(ExtensibleClient.java:535)
    at com.google.code.facebookapi.ExtensibleClient.callMethod(ExtensibleClient.java:472)
    at com.google.code.facebookapi.FacebookJsonRestClient.auth_getSession(FacebookJsonRestClient.java:278)

谁能告诉我这段代码有什么问题?使用 java api (v. 2.1.1) 在桌面模式下访问 facebook 应用程序的正确方法是什么。

感谢您的帮助。

问候 纳比尔·穆赫塔尔

【问题讨论】:

    标签: java authentication facebook


    【解决方案1】:

    据我了解 FB 的 API,您不应该手动提供用户名和密码,而是让用户手动输入它们,然后允许 Facebook 登录将用户重定向回您的应用程序。这意味着您无需提供“email”和“pass”,而是提供“next”和“cancel” URL:s。

    这纯粹是 FB API 的一个安全特性,虽然其背后的理论是好的,但执行远非最佳。

    【讨论】:

      【解决方案2】:

      在 Google 代码网站上查看此 discussion thread。该线程中有一个指向 wiki 页面的链接,该页面解释了如何进行桌面身份验证。

      【讨论】:

        猜你喜欢
        • 2012-08-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-30
        • 1970-01-01
        • 2011-07-17
        • 1970-01-01
        • 2022-12-12
        相关资源
        最近更新 更多