开发者

Uploading Image in Friend's Wall/account in Facebook Through Android

开发者 https://www.devze.com 2023-03-05 04:10 出处:网络
I want to upload an image to my friend\'s account/wall using Facebook Api Through My application in android.

I want to upload an image to my friend's account/wall using Facebook Api Through My application in android. I am able to upload the image to my acc开发者_运维百科ount, but now I am trying to make it more functional and trying to upload the image on friend's wall/accounts which I am selecting through my Android Application. I have tried to do it but no success. Plz help me... Thanks in Advance


Use this code in your method

File file=new File(murl);
InputStream is;
try {
    is = new FileInputStream(file);
    Drawable d;
    long length = file.length();
    if (length > Integer.MAX_VALUE) {
        // File is too large
    }
    byte[] bytes = new byte[(int)length];
    ByteArrayOutputStream bout=new    ByteArrayOutputStream();
    // Read in the bytes
    int offset = 0;
    int numRead = 0;
    while (offset < bytes.length
           && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
        offset += numRead;       
    }
    bout.write(bytes);
    bout.flush();
    //Bitmap bm=BitmapFactory.decodeByteArray(bytes,0,bytes.length);
    //d=new BitmapDrawable(bm);
    //mPostButton.setBackgroundDrawable(d);
    //p.putString("to","1300750213");
    //p.putString("caption","my card");
    EditText title_txt=(EditText) findViewById(R.id.fb_upload_txt);

    for(int i =0;i<frnd_list_id.length/2;i++){
        if(frnd_list_id[i]!="0"){
            Bundle p=new Bundle();
            p.putString("method","photos.upload");
            p.putString("caption",title_txt.getEditableText().toString());
            p.putByteArray("picture",bytes);
            System.out.println(frnd_list_id[i].trim());
            p.putString("target_id",frnd_list_id[i].trim());
            mAsyncRunner.request(null,p,"POST",new WallPostRequestListener(),null);
        }
    }
//System.out.println("hi");
} catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消