Android Facebook 图形 API

发布于 2024-10-19 21:13:57 字数 2081 浏览 1 评论 0原文

有人有如何使用 Android Graph API 的示例吗?

我被困在基础知识中,比如在 Facebook 上发布文字到墙上。

我正在使用适用于 Android 的 Facebook SDK。这是我到目前为止所得到的:

    Bundle params = new Bundle();
    params.putString("message", "picture caption");

    AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
    mAsyncRunner.request("me/feed", params, "POST", new RequestListener() {

        @Override
        public void onMalformedURLException(MalformedURLException e, Object state) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onIOException(IOException e, Object state) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onFileNotFoundException(FileNotFoundException e, Object state) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onFacebookError(FacebookError e, Object state) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onComplete(String response, Object state) {
            // TODO Auto-generated method stub

        }
    }, "foo");

什么也没发生,我的 Logcat 说:

03-02 22:10:02.973: WARN/Bundle(1930): Key message expected byte[] but value was a java.lang.String.  The default value <null> was returned.
    03-02 22:10:02.983: WARN/Bundle(1930): Attempt to cast generated internal exception:
    03-02 22:10:02.983: WARN/Bundle(1930): java.lang.ClassCastException: java.lang.String
    03-02 22:10:02.983: WARN/Bundle(1930):     at android.os.Bundle.getByteArray(Bundle.java:1305)
    03-02 22:10:02.983: WARN/Bundle(1930):     at com.facebook.android.Util.encodePostBody(Util.java:63)
    03-02 22:10:02.983: WARN/Bundle(1930):     at com.facebook.android.Util.openUrl(Util.java:182)
    03-02 22:10:02.983: WARN/Bundle(1930):     at com.facebook.android.Facebook.request(Facebook.java:559)
    03-02 22:10:02.983: WARN/Bundle(1930):     at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:253)

Has anyone got an example of how to use the Android Graph API?

I am stuck with the basics, like posting text to the wall on Facebook.

I'm using the Facebook SDK for Android. Here is what I have so far:

    Bundle params = new Bundle();
    params.putString("message", "picture caption");

    AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
    mAsyncRunner.request("me/feed", params, "POST", new RequestListener() {

        @Override
        public void onMalformedURLException(MalformedURLException e, Object state) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onIOException(IOException e, Object state) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onFileNotFoundException(FileNotFoundException e, Object state) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onFacebookError(FacebookError e, Object state) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onComplete(String response, Object state) {
            // TODO Auto-generated method stub

        }
    }, "foo");

Nothing happens, and my Logcat says:

03-02 22:10:02.973: WARN/Bundle(1930): Key message expected byte[] but value was a java.lang.String.  The default value <null> was returned.
    03-02 22:10:02.983: WARN/Bundle(1930): Attempt to cast generated internal exception:
    03-02 22:10:02.983: WARN/Bundle(1930): java.lang.ClassCastException: java.lang.String
    03-02 22:10:02.983: WARN/Bundle(1930):     at android.os.Bundle.getByteArray(Bundle.java:1305)
    03-02 22:10:02.983: WARN/Bundle(1930):     at com.facebook.android.Util.encodePostBody(Util.java:63)
    03-02 22:10:02.983: WARN/Bundle(1930):     at com.facebook.android.Util.openUrl(Util.java:182)
    03-02 22:10:02.983: WARN/Bundle(1930):     at com.facebook.android.Facebook.request(Facebook.java:559)
    03-02 22:10:02.983: WARN/Bundle(1930):     at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:253)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你在我安 2024-10-26 21:13:57

试试这个

Bundle params = new Bundle();
params.putString(Facebook.TOKEN, token);   
params.putString("message", "graph api");       
mAsyncRunner.request("/me/feed", params,"POST", new SampleUploadListener(),null);

你可以通过使用获取访问令牌

      token = mFacebook.getAccessToken();

try this

Bundle params = new Bundle();
params.putString(Facebook.TOKEN, token);   
params.putString("message", "graph api");       
mAsyncRunner.request("/me/feed", params,"POST", new SampleUploadListener(),null);

you can get access token by using

      token = mFacebook.getAccessToken();
无所谓啦 2024-10-26 21:13:57

你可以这样做:--
在捆绑消息中给出描述,如果您想分享服务器上的一些图像,您可以提供链接,如下所示

 Bundle params = new Bundle();
        params.putString("message", "description");
        params.putString("link","your image url" );

new GraphRequest( AccessToken.getCurrentAccessToken(),
            "me/feed",
            params,
            HttpMethod.POST,
            new GraphRequest.Callback() {
                @Override
                public void onCompleted(GraphResponse response) {
                    Log.d(TAG, "" + response.toString());
                    try {
                        JSONObject jsonObject = new JSONObject(response.getRawResponse());
                        if (jsonObject != null) {
                            String postId = jsonObject.getString("id");
                            if (postId != null && !postId.equalsIgnoreCase("")) {
                                hideProgressDialog();
                                Log.d("postId", "" + postId);
                            } else {
                                hideProgressDialog();
                                Utils.showToast(getActivity(), getResources().getString(R.string.txt_try_again));
                            }
                        } else {
                            hideProgressDialog();
                            Utils.showToast(getActivity(), getResources().getString(R.string.txt_try_again));
                        }

                    } catch (JSONException e) {
                        hideProgressDialog();
                        e.printStackTrace();
                    } catch (Throwable e) {
                        hideProgressDialog();
                        e.printStackTrace();
                    }

                }
            }).executeAsync();

You can do this like :--
give description in bundle message and if u want to share some image from server u can provide link as i given below

 Bundle params = new Bundle();
        params.putString("message", "description");
        params.putString("link","your image url" );

new GraphRequest( AccessToken.getCurrentAccessToken(),
            "me/feed",
            params,
            HttpMethod.POST,
            new GraphRequest.Callback() {
                @Override
                public void onCompleted(GraphResponse response) {
                    Log.d(TAG, "" + response.toString());
                    try {
                        JSONObject jsonObject = new JSONObject(response.getRawResponse());
                        if (jsonObject != null) {
                            String postId = jsonObject.getString("id");
                            if (postId != null && !postId.equalsIgnoreCase("")) {
                                hideProgressDialog();
                                Log.d("postId", "" + postId);
                            } else {
                                hideProgressDialog();
                                Utils.showToast(getActivity(), getResources().getString(R.string.txt_try_again));
                            }
                        } else {
                            hideProgressDialog();
                            Utils.showToast(getActivity(), getResources().getString(R.string.txt_try_again));
                        }

                    } catch (JSONException e) {
                        hideProgressDialog();
                        e.printStackTrace();
                    } catch (Throwable e) {
                        hideProgressDialog();
                        e.printStackTrace();
                    }

                }
            }).executeAsync();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文