2011-05-12 47 views
0

我想通过我的应用程序在Android上使用Facebook Api将图像上传到我朋友的帐户/墙上。 我可以将图片上传到我的帐户,但现在我正在努力使其更加实用,并尝试将图片上传到我通过Android应用程序选择的朋友墙/帐户上。 我试图做到这一点,但没有成功。 PLZ帮我... 由于提前在Facebook上通过Android上传朋友墙/帐户中的图片

回答

1

使用此代码在您的方法

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

从w我明白,你最终会同时触发'frnd_list_id.length/2'同时所有人向Facebook发送请求。猜测这可能是更好的策略来实现你自己的Thread,你可以同时多次同时调用'Facebook.request(...)'。 – harism 2011-05-14 21:03:41

相关问题