无法投递从绘制图像在Facebook [英] Unable to post an image from drawable to facebook

查看:108
本文介绍了无法投递从绘制图像在Facebook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从可绘制文件夹到饲料对话传递的图像。但我无法查看Facebook上的对话的图像。参数的其余均为可用。我使用Facebook的SDK 3.5。这里是功能表示饲料对话框

 私人无效publishFeedDialog(){


        点阵位图= BitmapFactory.de codeResource(this.getResources(),R.drawable.ic_launcher);
        ByteArrayOutputStream流=新ByteArrayOutputStream();
        bitmap.com preSS(Bitmap.Com pressFormat.JPEG,100,流);
        byte []的位图数据= stream.toByteArray();

        捆绑PARAMS =新包();
        params.putByteArray(图片报,位图数据);
        params.putString(名,Facebook的SDK为Android);
        params.putString(标题,建立伟大的社会化应用,并获得更多的安装。);
        params.putString(说明,在Facebook的SDK为Android使得它更容易和更快的开发Facebook的整合Android应用。);
        params.putString(链接,https://developers.facebook.com/android);
        //params.putString("picture,https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png);


        WebDialog feedDialog =(
            新WebDialog.FeedDialogBu​​ilder(getActivity()
                Session.getActiveSession(),
                PARAMS))
            .setOnCompleteListener(新OnCompleteListener(){

                @覆盖
                公共无效的onComplete(束值,
                    FacebookException错误){
                    如果(错误== NULL){
                        //当故事被张贴,呼应成功
                        //和文章ID。
                        最终的字符串postid = values​​.getString(的post_id);
                        如果(postId!= NULL){
                            Toast.makeText(getActivity(),
                                张贴的故事,ID:+ postId,
                                Toast.LENGTH_SHORT).show();
                        } 其他 {
                            //用户点击了取消按钮
                            Toast.makeText(getActivity()。getApplicationContext(),
                                发布取消,
                                Toast.LENGTH_SHORT).show();
                        }
                    }否则,如果(错误的instanceof FacebookOperationCanceledException){
                        //用户点击X按钮
                        Toast.makeText(getActivity()。getApplicationContext(),
                            发布取消,
                            Toast.LENGTH_SHORT).show();
                    } 其他 {
                        //通用,例如:网络错误
                        Toast.makeText(getActivity()。getApplicationContext(),
                            错误张贴的故事,
                            Toast.LENGTH_SHORT).show();
                    }
                }

            })
            。建立();
        feedDialog.show();
    }
 

解决方案

发布饲料将只与网址图像。

请参阅图片在饲料文档属性:<一href="https://developers.facebook.com/docs/reference/dialogs/feed/">https://developers.facebook.com/docs/reference/dialogs/feed/

如果你想从你的记忆发布的图像(如绘制文件夹),那么你需要使用: Request.newUploadPhotoRequest()

在这旁边,你可以使用这个简单的开源库,支持SDK 3.5做这样公布照片,饲料等以非常简单的方式操作:<一href="https://github.com/sromku/android-simple-facebook">https://github.com/sromku/android-simple-facebook

更新

选项1
您可以使用 Request.newUploadPhotoRequest(),但这种方法不允许添加任何附加属性,除了图像本身。

 位图位= BitmapFactory.de codeResource(this.getResources(),R.drawable.ic_launcher);
Request.newUploadPhotoRequest(Session.getActiveSession(),位图,新Request.Callback()
{
    @覆盖
    公共无效onCompleted(响应响应)
    {
        // ...处理响应...
    }
});
 

选项2
如果您想更多的属性添加到像描述的图像,然后做几乎相同,但与原始图形API调用。 Facebook的实施 Request.newUploadPhotoRequest()不完全一样,但没有设置附加属性。

 位图位= BitmapFactory.de codeResource(this.getResources(),R.drawable.ic_launcher);

捆绑PARAMS =新包();
params.putParcelable(图片报,位图);
params.putString(信息,这是图像的描述);
params.putString(地方,1235456498726); //取代图像的标识

请求请求=新的请求(会话,我/照片,捆绑,HttpMethod.POST,新Request.Callback()
{
    @覆盖
    公共无效onCompleted(响应响应)
    {
        // ...处理响应...
    }
});

RequestAsyncTask任务=新RequestAsyncTask(要求);
task.execute();
 

I am trying to pass an image from the drawables folder to the feed dialogue. But I am unable to view the image in facebook feed dialogue. Rest of the parameters are available. I am using facebook SDK 3.5. Here is the function for showing feed dialog.

 private void publishFeedDialog() {


        Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(),R.drawable.ic_launcher);
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
        byte[] bitMapData = stream.toByteArray();

        Bundle params = new Bundle();
        params.putByteArray("picture", bitMapData);
        params.putString("name", "Facebook SDK for Android");
        params.putString("caption", "Build great social apps and get more installs.");
        params.putString("description", "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
        params.putString("link", "https://developers.facebook.com/android");
        //params.putString("picture", "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");


        WebDialog feedDialog = (
            new WebDialog.FeedDialogBuilder(getActivity(),
                Session.getActiveSession(),
                params))
            .setOnCompleteListener(new OnCompleteListener() {

                @Override
                public void onComplete(Bundle values,
                    FacebookException error) {
                    if (error == null) {
                        // When the story is posted, echo the success
                        // and the post Id.
                        final String postId = values.getString("post_id");
                        if (postId != null) {
                            Toast.makeText(getActivity(),
                                "Posted story, id: "+postId,
                                Toast.LENGTH_SHORT).show();
                        } else {
                            // User clicked the Cancel button
                            Toast.makeText(getActivity().getApplicationContext(), 
                                "Publish cancelled", 
                                Toast.LENGTH_SHORT).show();
                        }
                    } else if (error instanceof FacebookOperationCanceledException) {
                        // User clicked the "x" button
                        Toast.makeText(getActivity().getApplicationContext(), 
                            "Publish cancelled", 
                            Toast.LENGTH_SHORT).show();
                    } else {
                        // Generic, ex: network error
                        Toast.makeText(getActivity().getApplicationContext(), 
                            "Error posting story", 
                            Toast.LENGTH_SHORT).show();
                    }
                }

            })
            .build();
        feedDialog.show();
    }

解决方案

Publish feed will work only with url to image.

See picture property under feed documentation: https://developers.facebook.com/docs/reference/dialogs/feed/

If you want to publish image from your memory (like drawable folder) then you need to use: Request.newUploadPhotoRequest()

Beside this, you can use this simple open source library that supports SDK 3.5 for doing actions like publish photo, feed and so on in a very simple way: https://github.com/sromku/android-simple-facebook

UPDATE

Option 1
You can use Request.newUploadPhotoRequest(), but this method doesn't allow you to add any additional property except the image itself.

Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(),R.drawable.ic_launcher);
Request.newUploadPhotoRequest(Session.getActiveSession(), bitmap , new Request.Callback()
{
    @Override
    public void onCompleted(Response response)
    {
        // ... handle the response...           
    }
});

Option 2
If you want to add additional properties to the image like description, then do almost the same but with raw graph api call. The facebook implementation of Request.newUploadPhotoRequest() does exactly the same but without setting additional properties.

Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(),R.drawable.ic_launcher);

Bundle params = new Bundle();
params.putParcelable("picture", bitmap);
params.putString("message", "This is the description of the image");
params.putString("place", "1235456498726"); // place id of the image

Request request = new Request(session, "me/photos", bundle, HttpMethod.POST, new Request.Callback()
{
    @Override    
    public void onCompleted(Response response)
    {
        // ... handle the response...
    }
});

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

这篇关于无法投递从绘制图像在Facebook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆