【问题标题】:Uploading Image in Friend's Wall/account in Facebook Through Android通过 Android 将图片上传到朋友的墙/Facebook 中的帐户
【发布时间】:2011-10-21 18:01:43
【问题描述】:

我想通过我在 android 中的应用程序使用 Facebook Api 将图像上传到我朋友的帐户/墙。 我可以将图像上传到我的帐户,但现在我正在尝试使其功能更强大,并尝试将图像上传到我通过 Android 应用程序选择的朋友的墙/帐户上。 我试过这样做,但没有成功。 请帮我... 提前致谢

【问题讨论】:

    标签: android facebook-java-api


    【解决方案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();
    }
    

    【讨论】:

    • 据我了解,您最终会触发frnd_list_id.length/2 同时线程,所有线程都同时向 Facebook 发送请求。猜测实现自己的线程可能是更好的策略,您可以在其中多次同步调用Facebook.request(...),一次一个。
    猜你喜欢
    • 1970-01-01
    • 2011-10-05
    • 1970-01-01
    • 2011-09-25
    • 2012-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多