Android 3.0中的Facebook 3.0

时间:2013-06-05 03:01:13

标签: android facebook-android-sdk

我创建了一个需要自动将状态发布到Facebook墙的应用程序。

我已使用SDK 3.0成功启用了登录/注销会话。我正在尝试通过按下按钮在我的墙上发布状态。

我尝试了以下内容:

Facebook Publish to feed

我无法发布它。点击post to wall按钮(我已创建) - 我得到一个带有进度条的新屏幕,几秒钟后 - 它返回主屏幕。我墙上没有任何更新。

更新

如果我禁用:

    if (!isSubsetOf(PERMISSIONS, permissions)) {
        pendingPublishReauthorization = true;
        Session.NewPermissionsRequest newPermissionsRequest = new Session
                .NewPermissionsRequest(this, PERMISSIONS);
    session.requestNewPublishPermissions(newPermissionsRequest);
        return;
    } 

这部分代码。我可以发布消息。如果我这样做这只适用于我的手机而不是不同的手机。我该如何解决这个问题?

更新-2:

在我评论返回部分之后 - 我得到一个强制关闭但我得到了权限对话框。

这里是错误,它指向:

JSONObject graphResponse = response.getGraphObject()。getInnerJSONObject();

这是错误: 06-05 12:50:43.932:E / AndroidRuntime(21933):致命异常:主要 06-05 12:50:43.932:E / AndroidRuntime(21933):java.lang.NullPointerException 06-05 12:50:43.932:E / AndroidRuntime(21933):at com.test.fbtest.Sessionvalid $ 1.onCompleted(Sessionvalid.java:216) 06-05 12:50:43.932:E / AndroidRuntime(21933):at com.facebook.Request $ 4.run(Request.java:1240) 06-05 12:50:43.932:E / AndroidRuntime(21933):在android.os.Handler.handleCallback(Handler.java:725) 06-05 12:50:43.932:E / AndroidRuntime(21933):在android.os.Handler.dispatchMessage(Handler.java:92) 06-05 12:50:43.932:E / AndroidRuntime(21933):在android.os.Looper.loop(Looper.java:137) 06-05 12:50:43.932:E / AndroidRuntime(21933):在android.app.ActivityThread.main(ActivityThread.java:5041) 06-05 12:50:43.932:E / AndroidRuntime(21933):at java.lang.reflect.Method.invokeNative(Native Method) 06-05 12:50:43.932:E / AndroidRuntime(21933):at java.lang.reflect.Method.invoke(Method.java:511) 06-05 12:50:43.932:E / AndroidRuntime(21933):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:793) 06-05 12:50:43.932:E / AndroidRuntime(21933):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 06-05 12:50:43.932:E / AndroidRuntime(21933):at dalvik.system.NativeStart.main(Native Method)

不确定为什么我会在那里收到错误?

1 个答案:

答案 0 :(得分:1)

删除return statement.it对我有用。

if (!isSubsetOf(PERMISSIONS, permissions)) {
        pendingPublishReauthorization = true;
        Session.NewPermissionsRequest newPermissionsRequest = new Session
                .NewPermissionsRequest(this, PERMISSIONS);
    session.requestNewPublishPermissions(newPermissionsRequest);
       'remove return statement=>' return;
    } 

工作样本,

private void publishStory()
        {


List<String> PERMISSIONS = Arrays.asList("publish_actions");
            Session session = Session.getActiveSession();

            if (session != null)
                {

                    // Check for publish permissions
                    List<String> permissions = session.getPermissions();
                    if (!isSubsetOf(PERMISSIONS, permissions))
                        {
                            Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(this, PERMISSIONS);
                            session.requestNewPublishPermissions(newPermissionsRequest);
                        }

                    Bundle postParams = new Bundle();
                    postParams.putString("name", "Sample google for for Android");
                    postParams.putString("caption", "world of data");
                    postParams.putString("description","Various religios music, chants, mantras, christian songs, islamic music, quran and more.");
                    postParams.putString("link", "http://www.google.com/");
                    postParams.putString("picture", "http://www.userlogos.org/files/logos/veinedstorm/raaga.png");

                    Request.Callback callback = new Request.Callback()
                        {
                            public void onCompleted(Response response)
                                {
                                    JSONObject graphResponse = response.getGraphObject().getInnerJSONObject();
                                    String postId = null;
                                    try
                                        {
                                            postId = graphResponse.getString("id");
                                        }
                                    catch (JSONException e)
                                        {
                                            Log.i("JSON", "JSON error " + e.getMessage());
                                        }
                                    FacebookRequestError error = response.getError();
                                    Log.e("post response",response.toString());
                                    if (error != null)
                                        {
                                            Toast.makeText(checkAndPostActivity.this, error.getErrorMessage(), Toast.LENGTH_SHORT)
                                                    .show();
                                        }
                                    else
                                        {
                                            Toast.makeText(checkAndPostActivity.this, postId, Toast.LENGTH_LONG).show();
                                        }
                                }
                        };

                    Request request = new Request(session, "me/feed", postParams, HttpMethod.POST, callback);

                    RequestAsyncTask task = new RequestAsyncTask(request);
                    task.execute();
                }

        }



private boolean isSubsetOf(Collection<String> subset, Collection<String> superset)
        {
            for (String string : subset)
                {
                    if (!superset.contains(string))
                        {
                            return false;
                        }
                }
            return true;
        }