android - 在android fb graph api中获取空响应

标签 android facebook facebook-graph-api

我一直在尝试使用 fb graph api 但我得到的 reponsenull 当我尝试在我的 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/

相关文章:

Android sqlite,限制数据库中的行数

facebook - FB如何在不重新加载页面的情况下刷新页面(xmlHttpRequest)但后退按钮仍然有效?

php - PHP 网站中的 Facebook feed、twitter twits 和链接连接

ios - 移动应用好友邀请/通知

ios - 为什么 facebook 在 iOS 中返回最友好的 0?如何检索 fb 好友列表并将其存储以进行解析?

android - 在对话框关闭时调用上一个 Activity 方法

android - 将动态 TextView 添加到 RecyclerView ViewHolder 会弄乱 View

javascript - 如何从 Facebook API 返回的 jsonp 中获取数据作为封面图片

android - 使用 Gdx.app.getPreferences 检索首选项

facebook - 对话发送 - 多个 friend