的Andr​​oid如何上传图片朋友的墙上用facebook Android SDK中 [英] Android how to post picture to friend's wall with facebook android sdk

查看:122
本文介绍了的Andr​​oid如何上传图片朋友的墙上用facebook Android SDK中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以张贴到Facebook好友的墙上的文字信息,但如何才能张贴图片,图片使用的Andr​​oid SDK的Facebook朋友的墙?

当我打印出来的墙可变它确实表明正确USER_ID /饲料。张贴RequestListener的的onComplete功能后不会被调用,但并没有什么张贴到好友留言。

下面的例子code,我们正在尝试使用:

 捆绑PARAMS =新包();
params.putString(法,photos.upload);
params.putString(标题,photoCaption.getText()的toString());
params.putByteArray(图片,数据);

AsyncFacebookRunner mAsyncRunner =新AsyncFacebookRunner(脸谱);

字符串墙= NULL;
墙= fArray.getJSONObject(POS).getString(ID)的toString()+/饲料。

mAsyncRunner.request(墙,PARAMS,POST,新RequestListener(){

    公共无效的onComplete(字符串响应,对象状态){
        Log.d(文字,脸谱后完成);
    }

    公共无效onIOException(IOException异常E,对象状态){
        Log.d(文字,脸谱后onIOException);
    }

    公共无效onFileNotFoundException(FileNotFoundException异常即对象的状态){
        Log.d(文字,脸谱后onFileNotFoundException);
    }

    公共无效onMalformedURLException(MalformedURLException的E,对象的状态){
        Log.d(文字,脸谱后onMalformedURLException);
    }

    公共无效onFacebookError(FacebookError即对象的状态){
        Log.d(文字,Facebook发布错误);
    }

}, 空值);
 

这是我如何得到好友列表:

  AsyncFacebookRunner mAsyncRunner =新AsyncFacebookRunner(脸谱);

mAsyncRunner.request(我的/朋友,新RequestListener(){

    公共无效的onComplete(字符串响应,对象状态){
    尝试 {
        jObject =新的JSONObject(响应);
        fArray = jObject.getJSONArray(数据);
 

解决方案

这是我用它来发布图片在墙上的方法,它从一个网址张贴事先知情同意,但你可以改变它把一个字节[] 的PIC代替。出现在图像上面的信息和字幕出现在画面的右侧。

 保护无效postPicToWall(字符串userid,字符串味精,标题字符串,字符串picURL){
    尝试 {
        如果(isSession()){
            字符串响应= mFacebook.request((用户ID == NULL)我:用户ID);

            捆绑PARAMS =新包();
            params.putString(信息,味精);
            params.putString(标题,字幕);
            params.putString(图片报,picURL);

            响应= mFacebook.request(((用户ID == NULL)我:用户ID)+/饲料,PARAMS,POST);

            Log.d(测试,响应);
            如果(响应==空|| response.equals()||
                    response.equals(假)){
                Log.v(错误,空白响应);
            }
        } 其他 {
            //没有登录,所以重新登录
            Log.d(TAG,sessionNOTValid,重新登录);
            mFacebook.authorize(此,烫发,新LoginDialogListener());
        }
    }赶上(例外五){
        e.printStackTrace();
    }
}
 

编辑:

要发布一个byte [],而不是一个URL到PIC,然后替换该行

params.putString(图片,picURL);

params.putByteArray(图片报,getIntent()getExtras()getByteArray(数据));

其中,数据阵列。

We can post to facebook friend's wall a text message, but how can we post an image, a picture to a friend's wall using Android Facebook SDK?

When I print out the wall variable it does show correctly USER_ID/feed. After posting the onComplete function of the RequestListener does get called, but there is nothing posted to the friends wall.

Here's example code we're trying to use:

Bundle params = new Bundle();
params.putString("method", "photos.upload");
params.putString("caption", photoCaption.getText().toString());
params.putByteArray("picture", data);

AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);

String wall = null;
wall = fArray.getJSONObject(pos).getString("id").toString() + "/feed";

mAsyncRunner.request(wall, params,"POST", new RequestListener(){

    public void onComplete(String response, Object state) {
        Log.d("text","facebook post complete");
    }

    public void onIOException(IOException e, Object state) {
        Log.d("text","facebook post onIOException");
    }

    public void onFileNotFoundException(FileNotFoundException e, Object state) {
        Log.d("text","facebook post onFileNotFoundException");
    }

    public void onMalformedURLException(MalformedURLException e, Object state) {
        Log.d("text","facebook post onMalformedURLException");
    }

    public void onFacebookError(FacebookError e, Object state) {
        Log.d("text","facebook post error");
    }

}, null);

This is how I get the list of friends:

AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);

mAsyncRunner.request("me/friends", new RequestListener(){

    public void onComplete(String response,Object state) {
    try {
        jObject = new JSONObject(response);
        fArray = jObject.getJSONArray("data"); 

解决方案

This is the method i use to post a picture to a wall, it posts a pic from a URL but you can change it to put a byte[] for the pic instead. The message appears above the picture and the caption appears to the right of the picture.

protected void postPicToWall(String userID, String msg, String caption, String picURL){
    try {
        if (isSession()) {
            String response = mFacebook.request((userID == null) ? "me" : userID);

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

            response = mFacebook.request(((userID == null) ? "me" : userID) + "/feed", params, "POST");       

            Log.d("Tests",response);
            if (response == null || response.equals("") || 
                    response.equals("false")) {
                Log.v("Error", "Blank response");
            }
        } else {
            // no logged in, so relogin
            Log.d(TAG, "sessionNOTValid, relogin");
            mFacebook.authorize(this, PERMS, new LoginDialogListener());
        }
    }catch(Exception e){
        e.printStackTrace();
    }
}

EDIT:

To post a byte[] rather than a url to a pic then replace the line

params.putString("picture", picURL); with

params.putByteArray("picture", getIntent().getExtras().getByteArray("data"));

where data is your array.

这篇关于的Andr​​oid如何上传图片朋友的墙上用facebook Android SDK中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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