0

我无法从 SD 卡上传 Facebook 上的图片......我使用了下面的代码......但它没有给我错误但同时它没有上传图片

     byte[] data = null;
     try {
         FileInputStream fis = new FileInputStream(filepath);
         BitmapFactory.Options options = new BitmapFactory.Options();                   
            options.inSampleSize = 2; 
         Bitmap bi = BitmapFactory.decodeStream(fis);

         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
         data = baos.toByteArray();  
      } catch (FileNotFoundException e) { 
         e.printStackTrace();
         Log.d("onCreate", "debug error  e = " + e.toString());
      }     

         Bundle params = new Bundle(); 
         params.putString("method", "photos.upload");  
         params.putByteArray("picture", data);
4

2 回答 2

1

试试下面的 SDCard 发布图片的片段:

将图像转换为位图并继续

private void postToWall() {   
    AsyncFacebookRunner mAsyncRunner = new   AsyncFacebookRunner(facebook);
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bm.compress(Bitmap.CompressFormat.PNG, 100, stream);  // where bm is bitmap from Sdcard
    byte[] byteArray = stream.toByteArray();
    Bundle param = new Bundle();
    param = new Bundle();
    param.putString("message", "All");
    param.putString("filename", "TEst");
    param.putByteArray("image", byteArray);
    mAsyncRunner.request("me/photos", param, "POST", new fbRequestListener(), null);
  }

  public class fbRequestListener implements RequestListener {

      @Override
      public void onComplete(String response, Object state) {
          // TODO Auto-generated method stub
          Log.d("RESPONSE",""+response);

      }

      @Override
      public void onIOException(IOException e, Object state) {
          // TODO Auto-generated method stub
          Log.d("RESPONSE",""+e);

      }

      @Override
      public void onFileNotFoundException(FileNotFoundException e,
              Object state) {
          // TODO Auto-generated method stub
          Log.d("RESPONSE",""+e);

      }

      @Override
      public void onMalformedURLException(MalformedURLException e,
              Object state) {
          // TODO Auto-generated method stub

      }

      @Override
      public void onFacebookError(FacebookError e, Object state) {
          // TODO Auto-generated method stub
          Log.d("RESPONSE",""+e);

      }

      }
于 2012-06-20T06:30:55.470 回答
0

你必须这样做:

 mAsyncRunner = new AsyncFacebookRunner(fbObj);  
  mAsyncRunner.request(null, parameters, "POST",
                        new RequestListener() {

                            @Override
                            public void onMalformedURLException(
                                    MalformedURLException e, Object state) {
                                // TODO Auto-generated method stub

                            }

                            @Override
                            public void onIOException(IOException e, Object state) {
                                // TODO Auto-generated method stub

                            }

                            @Override
                            public void onFileNotFoundException(
                                    FileNotFoundException e, Object state) {
                                // TODO Auto-generated method stub

                            }

                            @Override
                            public void onFacebookError(FacebookError e,
                                    Object state) {
                                // TODO Auto-generated method stub

                            }

                            @Override
                            public void onComplete(String response, Object state) {
                                // TODO Auto-generated method stub
                                Log.i("upload", "image uploaded!!!! " + response);
                            }
                        }, null);
于 2012-06-20T06:18:43.717 回答