在Android中使用Facebook SDK3时出现错误代码110

时间:2013-07-10 09:38:59

标签: android android-facebook

我正在尝试使用来自android的facebook sdk发送请求。

我就是这样做的:

private void sendInviteRequestDialog() {
        Bundle params = new Bundle();
        params.putString("id", USER_ID);
        params.putString("to", "xxxx"); 
        showDialogWithoutNotificationBar("apprequests", params);
}

 WebDialog requestsDialog = (
                    new WebDialog.RequestsDialogBuilder(HelloActivity.this,
                            Session.getActiveSession(),
                            params))
                            .setOnCompleteListener(new OnCompleteListener() {

                                @Override
                                public void onComplete(Bundle values,
                                        FacebookException error) {
                                    if (error != null) {
                                        if (error instanceof FacebookOperationCanceledException) {
                                            Toast.makeText(HelloActivity.this.getApplicationContext(), 
                                                    "Request cancelled", 
                                                    Toast.LENGTH_SHORT).show();
                                        } else {
                                            Toast.makeText(HelloActivity.this.getApplicationContext(), 
                                                    "Network Error", 
                                                    Toast.LENGTH_SHORT).show();
                                        }
                                    } else {
                                        final String requestId = values.getString("request");
                                        if (requestId != null) {
                                            Toast.makeText(HelloActivity.this.getApplicationContext(), 
                                                "Request sent",  
                                                Toast.LENGTH_SHORT).show();
                                        } else {
                                            Toast.makeText(HelloActivity.this.getApplicationContext(), 
                                                    "Request cancelled", 
                                                    Toast.LENGTH_SHORT).show();
                                        }
                                    }   
                                }

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

所以,我登录了fb,我可以看到我的朋友列表,发布在我的墙上,但我无法发送邀请邀请到我的应用程序。在计算机上的Web浏览器中使用相同的URL工作,但不在Android应用程序中。 这是我收到的错误:

An error occured. Please try again later.
API Error code: 110
API Error Description: Invalid user id
Error Message: Missing user cookie(to validate session user)

我的权限是:

private static final List<String> PERMISSIONS = Arrays.asList(
            "publish_actions", "publish_stream", "offline_access", "email",
            "basic_info", "user_likes", "user_birthday", "status_update",
            "create_note", "share_item", "user_status");

此刻我很失落,不要这样。 任何想法都会很棒。 谢谢。

2 个答案:

答案 0 :(得分:1)

我浪费了很多时间,但已经找到了解决方案。 Facebook问题是缓存。我创建get方法,清除缓存是从缓存创建的标记:

private Session getFBSession() {
    Session session = Session.getActiveSession();

    if (session == null) {
        session = new Session(getActivity());
        Session.setActiveSession(session);

        if (session.getState() == SessionState.CREATED_TOKEN_LOADED)
            session.closeAndClearTokenInformation();
    }

    return session;
}

但对你而言这并不是因为闭门会话没有打开会话。因此,您需要在按钮按下后重新打开会话:

private void publishFeedDialog() {
    Session session = getFBSession();

    if (!session.isOpened())
        session.openForRead(new Session.OpenRequest(this).setCallback(facebookForShareCallback));
    else
        session.openActiveSession(getActivity(), this, true, facebookForShareCallback);
}

回调应该是这样的:

private Session.StatusCallback facebookForShareCallback = new Session.StatusCallback() {
    @Override
    public void call(Session session, SessionState state, Exception exception) {
        if (session.isOpened()) {
            Bundle params = new Bundle();
            params.putString("name", "name");
            params.putString("caption", event.title);
            params.putString("description", event.descLong);
            params.putString("link", "http://www.lt");
            params.putString("picture", event.logo);

            WebDialog feedDialog = new WebDialog.FeedDialogBuilder(getActivity(), session, params)
                    .build();

            feedDialog.show();
        } else if (state == SessionState.CLOSED_LOGIN_FAILED) {
            if (checkin != null)
                Toast.makeText(getActivity(), getString(R.string.facebook_error), Toast.LENGTH_LONG).show();
        }
    }
};

答案 1 :(得分:0)

你也必须发送Facebook令牌

String Token = session.getAccessToken();

然后

    params.putString("token", Token);        
    params.putString("id", USER_ID);
    params.putString("to", "xxxx"); 

它应该是有效的