我使用下面的代碼整合FB圖形API在我的項目:FB圖形API在建的apk不工作
private void integrateFacebook(){
fbLoginButton =(LoginButton)findViewById(R.id.fb_login_button);
callbackManager = CallbackManager.Factory.create();
mLoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("public_profile"));
fbLoginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Log.d("Facebook", "Facebook Login Successful!");
token = loginResult.getAccessToken().toString();
Log.d("Facebook", "User ID : " + loginResult.getAccessToken().getUserId());
GraphRequest request = GraphRequest.newMeRequest(
accessToken,
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
// Insert your code here
try {
String name = "";
String id =object.getString("id");
String img_url ="https://graph.facebook.com/"+id+"/picture?type=large";
String email= "";
if(object.has("id")){
name = object.getString("name");
}
if(object.has("email")){
email=object.getString("email");
}
if(object.has("email")){
email=object.getString("email");
}
UserActivation.getsharedInstance(getApplicationContext()).setUserName(name);
UserActivation.getsharedInstance(getApplicationContext()).setUserName(email);
SharedPref.getSharedPref().setValue(getApplicationContext(),"img_url",img_url);
SharedPref.getSharedPref().setValue(getApplicationContext(),"user_email",email);
submitData(name,email,null,null,"1","facebook",img_url,id);
} catch (JSONException e) {
e.printStackTrace();
Log.d(TAG,e.toString());
}catch(Exception e){
Log.d(TAG,e.toString());
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id, name, photos, picture{url}, email");
// parameters.putString("access_token", token);
request.setParameters(parameters);
request.executeAsync();
}
現在在調試模式下工作,但是當我嘗試運行通過build.apk它給以下日誌中的錯誤: 請求無訪問令牌缺少應用程序ID或客戶端令牌。
如何解決這個問題。