Getting null response in android fb graph api

I am trying to use fb graph api

but reponse

I am getting when I try to get page messages in android app. null

I am trying to get page feeds from a page whose id I have used. I am expecting to receive a response to the feed graph. But I got it null response

.

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();
        }
    }
} 

      

+3


source to share


1 answer


I misused the group id and not the page. But now I changed it to 415004402015833 (page id). Now the posts are coming. Thanks for the help....



0


source







All Articles