我一直在尝试使用 fb graph api
但我得到的 reponse
是 null
当我尝试在我的 Android 应用程序中获取页面的帖子。
我正在尝试从我使用过其 ID 的页面获取页面提要。
我希望得到包含提要的图形响应。
但是我得到了一个空响应
。
public class fb extends Activity {
Button fbbt1;
CallbackManager callbackManager;
AccessTokenTracker accessTokenTracker;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fb);
try {
FacebookSdk.sdkInitialize(getApplicationContext());
fbbt1 = (Button) findViewById(R.id.fbbutton);
callbackManager = CallbackManager.Factory.create();
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
// App code
}
@Override
public void onCancel() {
// App code
// savedInstanceState
}
@Override
public void onError(FacebookException exception) {
// App code
Toast.makeText(fb.this, exception.toString(), Toast.LENGTH_LONG).show();
}
});
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("public_profile, user_groups"));
accessTokenTracker = new AccessTokenTracker() {
@Override
protected void onCurrentAccessTokenChanged(
AccessToken oldAccessToken,
AccessToken currentAccessToken) {
}
};
fbbt1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
getUserData(AccessToken.getCurrentAccessToken());
Toast.makeText(fb.this, "Access Token: "+ AccessToken.getCurrentAccessToken().getToken().toString(), Toast.LENGTH_LONG).show();
}
catch (Exception e){
Toast.makeText(fb.this, "error is: "+e.toString(), Toast.LENGTH_LONG).show();
}
}
});
}
catch (Exception e){
Toast.makeText(fb.this, e.toString(), Toast.LENGTH_LONG).show();
}
}
public void getUserData(AccessToken accessToken){
GraphRequest.newGraphPathRequest(
accessToken, "/ 415004402015833/posts",
new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse graphResponse) {
try {
Toast.makeText(fb.this, "Object Length is : " + graphResponse.getJSONObject().length(), Toast.LENGTH_LONG).show();
Toast.makeText(fb.this, "request was: " + graphResponse.getRequest(), Toast.LENGTH_LONG).show();
String resp = graphResponse.getRawResponse();
Toast.makeText(fb.this, "response is: " + resp, Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(fb.this, "error is: " + e.toString(), Toast.LENGTH_LONG).show();
}
}
}).executeAsync();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
@Override
protected void onDestroy() {
super.onDestroy();
try{
accessTokenTracker.stopTracking();}
catch (Exception e){
Toast.makeText(fb.this, "error is: "+e.toString(), Toast.LENGTH_LONG).show();
}
}
}
最佳答案
我错误地使用了组的 ID 而不是页面。但是现在,我已将其更改为 415004402015833(页面 ID)。现在,帖子来了。 感谢您的帮助....
关于android - 在android fb graph api中获取空响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30907807/