Android 使用Facebook API时,配置文件返回null
在代码下面运行时,profile.getProfile()返回null。Android 使用Facebook API时,配置文件返回null,android,facebook,Android,Facebook,在代码下面运行时,profile.getProfile()返回null。 我正在使用正确的哈希键和正确的应用程序ID。 我正在onDestory()方法中停止配置文件和访问跟踪程序 我没有使用任何facebook应用程序 有没有办法解决这个问题 @Override public void onCreate(Bundle savedInstane) { super.onCreate(savedInstane);
我正在使用正确的哈希键和正确的应用程序ID。
我正在onDestory()方法中停止配置文件和访问跟踪程序
我没有使用任何facebook应用程序 有没有办法解决这个问题
@Override
public void onCreate(Bundle savedInstane)
{
super.onCreate(savedInstane);
// Add code to print out the key hash
FacebookSdk.sdkInitialize(getActivity().getApplicationContext());
callbackManager = CallbackManager.Factory.create();
accessTokenTracker = new AccessTokenTracker() {
@Override
protected void onCurrentAccessTokenChanged(AccessToken accessToken, AccessToken accessToken1) {
}
};
profileTracker = new ProfileTracker() {
@Override
protected void onCurrentProfileChanged(Profile profile, Profile profile1) {
}
};
accessTokenTracker.startTracking();
profileTracker.startTracking();
}
private FacebookCallback<LoginResult> mcallBack = new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
AccessToken token = loginResult.getAccessToken();
Profile profile = Profile.getCurrentProfile();
Uri link = profile.getProfilePictureUri(20, 20);
Log.d("Message",link.toString());
display(profile);
}
};
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
void facebookLogin()
{
FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();
setContentView(R.layout.activity_signin);
LoginButton login = (LoginButton)findViewById(R.id.login_button_facebook);
login.setReadPermissions(Arrays.asList("public_profile", "user_friends"));
login.registerCallback(callbackManager, mcallBackFacebook);
}
@覆盖
创建时的公共void(Bundle savedInstane)
{
super.onCreate(savedInstane);
//添加代码以打印出密钥散列
sdkinInitialize(getActivity().getApplicationContext());
callbackManager=callbackManager.Factory.create();
accessTokenTracker=新的accessTokenTracker(){
@凌驾
受保护的onCurrentAccessTokenChanged无效(AccessToken AccessToken,AccessToken accessToken1){
}
};
profileTracker=新的profileTracker(){
@凌驾
更改当前配置文件时受保护的无效(配置文件配置文件,配置文件1){
}
};
accessTokenTracker.startTracking();
profileTracker.startTracking();
}
private FacebookCallback mcallBack=新建FacebookCallback(){
@凌驾
成功时公共无效(LoginResult LoginResult){
AccessToken token=loginResult.getAccessToken();
Profile Profile=Profile.getCurrentProfile();
urilink=profile.getProfilePictureUri(20,20);
Log.d(“Message”,link.toString());
显示(配置文件);
}
};
@凌驾
ActivityResult上的公共void(int请求代码、int结果代码、意图数据){
super.onActivityResult(请求代码、结果代码、数据);
callbackManager.onActivityResult(请求代码、结果代码、数据);
}
void facebookLogin()
{
sdkinInitialize(getApplicationContext());
callbackManager=callbackManager.Factory.create();
setContentView(R.layout.activity\u signin);
LoginButton login=(LoginButton)findViewById(R.id.login\u button\u facebook);
login.setReadPermissions(Arrays.asList(“public_profile”、“user_friends”);
registerCallback(callbackManager,mcallBackFacebook);
}
请按照以下步骤操作:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(this.getApplicationContext());
callbackManager = CallbackManager.Factory.create();
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(
JSONObject object,
GraphResponse response) {
// Call service for check facebook auth from server
try {
mFBID = encodeToBase64("" + object.get("email"));
System.out.println("Your facebook is is-----" + mFBID);
//YOUR CODE
} catch (JSONException e) {
e.printStackTrace();
}
}
});
//its will return id, name and email
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email");
request.setParameters(parameters);
request.executeAsync();
}
@Override
public void onCancel() {
Toast.makeText(LoginActivity.this, "Login Cancel", Toast.LENGTH_LONG).show();
}
@Override
public void onError(FacebookException exception) {
Toast.makeText(LoginActivity.this, exception.getMessage(), Toast.LENGTH_LONG).show();
}
});
setContentView(R.layout.XML);
}
试试看。。在这里工作正常在获取facebook详细信息之前,您是否已授予权限?我已按照您的步骤进行操作,但仍然不起作用。。为什么onSuccess会重复两次……第一次:在我的代码中声明mCallback,第二次在代码的onCreate()中。此外,我没有得到我需要放置读取权限的确切位置
LoginManager.getInstance().logInWithReadPermissions(_activity, Arrays.asList("public_profile", "email", "user_friends"));
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
callbackManager.onActivityResult(requestCode, resultCode, data);
}