2

是否有人通过获取用户凭据并允许类似于linkedin API的字段来帮助我为facebook提供OAuth访问令牌的示例。

我试着用喜欢

Configuration configuration =  createConfiguration();
        FacebookFactory facebookFactory = new FacebookFactory(configuration );
        Facebook facebookClient = facebookFactory.getInstance();
        AccessToken accessToken = null;
        try{
            OAuthSupport oAuthSupport = new OAuthAuthorization(configuration );
            accessToken = oAuthSupport.getOAuthAppAccessToken();

        }catch (FacebookException e) {
            logger.error("Error while creating access token " + e.getLocalizedMessage(), e);
        }

public Configuration createConfiguration() {
        ConfigurationBuilder confBuilder = new ConfigurationBuilder();

        confBuilder.setDebugEnabled(APIConfiguration.DEBUG_ENABLED);
        confBuilder.setOAuthAppId(APIConfiguration.APP_ID);
        confBuilder.setOAuthAppSecret(APIConfiguration.APP_SECRET);
        confBuilder.setUseSSL(APIConfiguration.USE_SSL);
        confBuilder.setJSONStoreEnabled(APIConfiguration.JSON_STORE_ENABLED);


        Configuration configuration = confBuilder.build();
        return configuration;
    }

我得到了访问令牌,但我可以搜索它显示的用户

严重:获取 facebook 用户时出错 {"error":{"message":"(#200) 必须具有有效的 access_token 才能访问此端点","type":"OAuthException","code":200}}

FacebookException [statusCode=403, response=HttpResponse{statusCode=403, responseAsString='{"error":{"message":"(#200) Must have a valid access_token to access this endpoint","type":"OAuthException","code":200}}
', is=sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@1232784a, streamConsumed=true}, errorType=OAuthException, errorMessage=(#200) Must have a valid access_token to access this endpoint, errorCode=200]
    at facebook4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:189)
    at facebook4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:65)
    at facebook4j.internal.http.HttpClientWrapper.get(HttpClientWrapper.java:93)
    at facebook4j.FacebookImpl.get(FacebookImpl.java:2095)
    at facebook4j.FacebookImpl.searchUsers(FacebookImpl.java:1799)
    at facebook4j.FacebookImpl.searchUsers(FacebookImpl.java:1795)

我将如何使用回调 url 获取 OAUTH 我尝试使用http://www.google.com的 redirect_uri但它没有提供任何代码。

这是我的 Java 控制台应用程序

4

3 回答 3

2

定义 accessToken 如下例:

accessToken = new AccessToken("CAACEdEose0cBAFpfeSxd3WFzkUfm4l4PTKtLblS0hpbOFQcanzYciYMCSuFNOgiZBEtjxWZCHvwU0iP4cTe7aHXeNB5nQOC88ECE1lzVvjNKPjXNsGmJfbNfGEULQ0zEfeTla3Puknj6AGcsPy5VKKEQdJ3FbJ20RRemtgAGh05kgXsXnLrdfCPq6e6eFyu8dWxL1ZBv0EZBe9le3m0U");

其中 accesToken 字符串是从https://developers.facebook.com/tools/accesstoken/获得的 在此处输入图像描述

于 2015-11-01T21:28:22.990 回答
0

我受到使用您的代码的启发,并且遇到了类似的错误。解决方案似乎是在 facebook 开发者中心 = https://developers.facebook.com/中正确注册应用程序,该应用程序必须由中心创建、编辑、提交和批准。

于 2013-06-29T11:45:24.317 回答
0

我认为你错过了这一行:

facebookClient.setOAuthAccessToken( accessToken );
于 2014-06-25T07:24:08.783 回答