1

我正在为 Android 使用更新的 Facebook SDK V3.0 final。我正在尝试向没有该应用程序的 Facebook 朋友发送应用程序请求。代码是:

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

当代码运行时,我从打印的响应中得到以下内容之一:

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

... 或者:

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

我有以下权限:publist_streampublish_actions.

解决问题后,我还想知道如何将一组收件人添加到应用请求中。

我不想使用 Facebook 对话框。

4

2 回答 2

1

试试这个:

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

这是向某人明确发送应用请求的正确方法。如果您不包含该to参数,用户可以选择他们想要发送给谁。

于 2013-01-15T05:00:15.583 回答
0
Response:  responseCode: unknown, graphObject: null, error: {HttpStatus: -1, errorCode: -1, errorType: null, errorMessage: null}, isFromCache:false}

这种情况通常与在您自己的线程上同时运行 FB 请求有关。我学会了使用任何一种的艰难方法

Request.executeAsync()

或者

RequestAsyncTask
于 2013-05-02T14:34:01.757 回答