Facebook4j身份验证问题

时间:2017-02-01 15:52:07

标签: java json facebook import

我正在尝试创建一个与facebook连接的java应用程序。我正在使用facebok4j来实现这一点,我在fb devolopers中创建了一个应用程序并获得了它的密钥和ID。但是当我传递它以获得一个访问令牌返回异常错误。请帮助我

java代码

import java.io.BufferedWriter; 
import java.io.File; 
import java.io.FileWriter; 
import java.io.IOException; 

import net.sf.json.JSONArray; 
import net.sf.json.JSONObject; 
import facebook4j.Facebook; 
import facebook4j.FacebookException; 
import facebook4j.FacebookFactory; 
import facebook4j.Post; 
import facebook4j.ResponseList;
import facebook4j.auth.AccessToken;
import facebook4j.auth.OAuthAuthorization;
import facebook4j.auth.OAuthSupport;
import facebook4j.conf.Configuration; 
import facebook4j.conf.ConfigurationBuilder; 
public class Fbsample {
public static  Configuration createConfiguration() 
{
    ConfigurationBuilder confBuilder = new ConfigurationBuilder();

    confBuilder.setDebugEnabled(true);
    confBuilder.setOAuthAppId("*****");
    confBuilder.setOAuthAppSecret("*****");
    confBuilder.setUseSSL(true);
    confBuilder.setJSONStoreEnabled(true);
    Configuration configuration = confBuilder.build();
    return configuration;
}
public static void main(String[] argv) throws FacebookException {
    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) {
        System.err.println("Error while creating access token " + e.getLocalizedMessage());
    }
    facebookClient.setOAuthAccessToken(accessToken);
//results in an error says {An active access token must be used to query information about the current user}
}

}

import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import facebook4j.Facebook; import facebook4j.FacebookException; import facebook4j.FacebookFactory; import facebook4j.Post; import facebook4j.ResponseList; import facebook4j.auth.AccessToken; import facebook4j.auth.OAuthAuthorization; import facebook4j.auth.OAuthSupport; import facebook4j.conf.Configuration; import facebook4j.conf.ConfigurationBuilder; public class Fbsample { public static Configuration createConfiguration() { ConfigurationBuilder confBuilder = new ConfigurationBuilder(); confBuilder.setDebugEnabled(true); confBuilder.setOAuthAppId("*****"); confBuilder.setOAuthAppSecret("*****"); confBuilder.setUseSSL(true); confBuilder.setJSONStoreEnabled(true); Configuration configuration = confBuilder.build(); return configuration; } public static void main(String[] argv) throws FacebookException { 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) { System.err.println("Error while creating access token " + e.getLocalizedMessage()); } facebookClient.setOAuthAccessToken(accessToken); //results in an error says {An active access token must be used to query information about the current user} } 现在我将我的令牌和ID指定为*。当创建访问令牌graph.facebook.com时运行其返回的'错误。提前感谢。

0 个答案:

没有答案