Apprequest of Android Facebook sdk 3.0

感情迁移 提交于 2019-12-08 06:01:17

问题


I am using the updated Facebook SDK V3.0 final for Android. I am trying to send app requests to facebook frineds who do not have the application. The code is:

public void fbookinvite(){

        Bundle postParams = new Bundle();
        postParams.putString("name", "X");
        postParams.putString("message", "DOWNLOAD X.");

        Session session = Session.getActiveSession();

        postParams.putString("access_token", session.getAccessToken());

        if (session==null||session.getState().isClosed()){
            System.out.println("session is null");
        }else{
            //meaning we are good to go.
            Request request = new Request(session,"/friend facebook id/apprequests", postParams, HttpMethod.POST, new Request.Callback() {

                @Override
                public void onCompleted(Response response) {

                    System.out.println("response was: "+response.toString());
                }

            });

            Request.executeBatchAsync(request);
        }       
    }

When the code runs I get one of the following from the printed response:

responseCode: 400, graphObject: null, error: {HttpStatus: 400, errorCode: 2, errorType: OAuthException, errorMessage: (#2) Failed to create any app request}, isFromCache:false

... or:

Response:  responseCode: unknown, graphObject: null, error: {HttpStatus: -1, errorCode: -1, errorType: null, errorMessage: null}, isFromCache:false}

I have the following permissions: publist_stream and publish_actions.

After solving the problem I'd also like to know how to add a group of recipients to the app request.

I do not want to use the Facebook dialog.


回答1:


Try this instead:

        Bundle params = new Bundle();   
        params.putString("message",
                "Learn how to make your Android apps social");
        params.putString("to", "YOUR_FRIEND_UID_HERE");
        WebDialog requestsDialog = (new WebDialog.RequestsDialogBuilder(
                this, Session.getActiveSession(), params))
                .setOnCompleteListener(new OnCompleteListener() {

                    @Override
                    public void onComplete(Bundle values,
                            FacebookException error) {
                        // your code here 
                    }

                }).build();
        requestsDialog.show();

This is the proper way to send an app request explicitly to someone. If you do not include the to parameter, the user can choose who they want to send to.




回答2:


Response:  responseCode: unknown, graphObject: null, error: {HttpStatus: -1, errorCode: -1, errorType: null, errorMessage: null}, isFromCache:false}

This is a scenario usually related with running simultaneous FB requests on your own threads. I learnt the hard way to use either

Request.executeAsync()

or

RequestAsyncTask


来源:https://stackoverflow.com/questions/14330680/apprequest-of-android-facebook-sdk-3-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!