如何在使用Facebook Android SDK调用我/照片标记朋友的同时提供“标签”参数值?

时间:2015-12-12 07:15:26

标签: android facebook facebook-graph-api facebook-android-sdk

在使用Facebook Android SDK调用我/照片来标记朋友时,我无法为“tags”参数提供正确的结构。 “tags”参数需要一个对象列表,其中每个对象再次具有4个具有不同数据类型的值,如此处所述 -

https://developers.facebook.com/docs/graph-api/reference/user/photos/#Creating

有人可以提供如何传递此“标记”字段值的示例代码吗?

1 个答案:

答案 0 :(得分:1)

您可以使用以下代码:

private FacebookCallback<LoginResult> mFacebookCallback = new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            Toast.makeText(mContext, "in LoginResult on success", Toast.LENGTH_LONG).show();

            AccessToken accessToken = loginResult.getAccessToken();

            /* make the share call */
            Bundle postParams = new Bundle();
            postParams.putString("message", "This is a test message");
            postParams.putString("picture", "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");
 // or you can use below 4 line for bitmap image
ByteArrayOutputStream bos = new ByteArrayOutputStream();
            bitmapCombine.compress(Bitmap.CompressFormat.PNG, 0, bos);
            byte[] bitmapdata = bos.toByteArray();
            postParams.putByteArray("picture", bitmapdata);
new GraphRequest(
                    AccessToken.getCurrentAccessToken(),
                    "/me/photos",  //photos
                    postParams,
                    HttpMethod.POST,
                    new GraphRequest.Callback() {
                        public void onCompleted(GraphResponse response) {

                            FacebookRequestError error = response.getError();
                            if(error == null) {
                               // JSONObject me = response.getJSONObject();
                                // String text = me.optString("email");

                                //shareEditText.setText("");

                                showSuccessDialog();
                                //bitmapCombine.recycle();
                            }
                            else
                            {
                                Toast.makeText(getContext(), error.getErrorMessage(),Toast.LENGTH_SHORT).show();
                            }
                        }
                    }
            ).executeAsync();
}

        @Override
        public void onCancel() {
            Log.d("VIVZ", "onCancel");
        }

        @Override
        public void onError(FacebookException e) {
            Log.d("VIVZ", "onError " + e.getMessage());
        }
    };