Android 应用程序未在 Facebook 上发布图片

发布于 2025-01-05 03:06:42 字数 3072 浏览 0 评论 0原文

您好,我正在使用教程在 Facebook 上发布图像,但它没有发布。请指导我做错了什么。我在手机上安装了 facebook.apk。我已经完全按照 Facebook 开发者指南中的描述进行操作。

这是错误...... 在此处输入图像描述

public class DummyActivity extends Activity {
Facebook facebook = new Facebook("xxxxxxxxxxxx");

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    facebook.authorize(this, new DialogListener() {
        public void onComplete(Bundle values) {
             byte[] data = null;

             Bitmap bi = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
             ByteArrayOutputStream baos = new ByteArrayOutputStream();
             bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
             data = baos.toByteArray();

             Bundle params = new Bundle();
             params.putString(Facebook.TOKEN, facebook.getAccessToken());
             params.putString("method", "photos.upload");
             params.putByteArray("picture", data);

             AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
             mAsyncRunner.request(null, params, "POST", new SampleUploadListener(), null);
        }

        public void onFacebookError(FacebookError error) {}

        public void onError(DialogError e) {}

        public void onCancel() {}         
    });
}




@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    facebook.authorizeCallback(requestCode, resultCode, data);
}

这是另一个类,

  public class SampleUploadListener implements RequestListener {

public void onComplete(String response, Object state) {
    // TODO Auto-generated method stub
      try {
            // process the response here: (executed in background thread)
            Log.d("Facebook-Example", "Response: " + response.toString());
            JSONObject json = Util.parseJson(response);
            final String src = json.getString("src");

            // then post the processed result back to the UI thread
            // if we do not do this, an runtime exception will be generated
            // e.g. "CalledFromWrongThreadException: Only the original
            // thread that created a view hierarchy can touch its views."

        } catch (JSONException e) {
            Log.w("Facebook-Example", "JSON Error in response");
        } catch (FacebookError e) {
            Log.w("Facebook-Example", "Facebook Error: " + e.getMessage());
        }

}

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

}

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

}

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

}

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

}

Hi I am using a tutorial to post image on facebook but its not posting. Please guide what i am doing wrong. I have facebook.apk installed on mobile. I have done extactly what is described on Facebook developer guiide.

Here is the error....
enter image description here

public class DummyActivity extends Activity {
Facebook facebook = new Facebook("xxxxxxxxxxxx");

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    facebook.authorize(this, new DialogListener() {
        public void onComplete(Bundle values) {
             byte[] data = null;

             Bitmap bi = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
             ByteArrayOutputStream baos = new ByteArrayOutputStream();
             bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
             data = baos.toByteArray();

             Bundle params = new Bundle();
             params.putString(Facebook.TOKEN, facebook.getAccessToken());
             params.putString("method", "photos.upload");
             params.putByteArray("picture", data);

             AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
             mAsyncRunner.request(null, params, "POST", new SampleUploadListener(), null);
        }

        public void onFacebookError(FacebookError error) {}

        public void onError(DialogError e) {}

        public void onCancel() {}         
    });
}




@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    facebook.authorizeCallback(requestCode, resultCode, data);
}

Here is another class,

  public class SampleUploadListener implements RequestListener {

public void onComplete(String response, Object state) {
    // TODO Auto-generated method stub
      try {
            // process the response here: (executed in background thread)
            Log.d("Facebook-Example", "Response: " + response.toString());
            JSONObject json = Util.parseJson(response);
            final String src = json.getString("src");

            // then post the processed result back to the UI thread
            // if we do not do this, an runtime exception will be generated
            // e.g. "CalledFromWrongThreadException: Only the original
            // thread that created a view hierarchy can touch its views."

        } catch (JSONException e) {
            Log.w("Facebook-Example", "JSON Error in response");
        } catch (FacebookError e) {
            Log.w("Facebook-Example", "Facebook Error: " + e.getMessage());
        }

}

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

}

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

}

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

}

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

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

心如狂蝶 2025-01-12 03:06:42

您使用了错误的参数!

查看photos.upload 文档

You are using wrong parametes!

Check the documentation of photos.upload

巡山小妖精 2025-01-12 03:06:42

像这样更改您的代码,

    Bundle params = new Bundle();

                try {
                    Bitmap bMap = BitmapFactory.decodeFile(config.downloaded_image_path);
                    Log.i("Path",config.downloaded_image_path);
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();  
                    bMap.compress(Bitmap.CompressFormat.PNG, 100, baos); //bm is the bitmap object   
                    byte[] b = baos.toByteArray(); 
                    params.putByteArray("photo", b);
                } catch  (Exception e) {
                    e.printStackTrace();
                }
                params.putString("caption", config.facebook_comment);
                Utility.mAsyncRunner.request("me/photos", params, "POST", new PhotoUploadListener(), null);

尝试将参数的键值更改为“照片”而不是“图片”,并在请求方法中为 GRaphApi 提供 null,这肯定是错误的。

Change your code like this,

    Bundle params = new Bundle();

                try {
                    Bitmap bMap = BitmapFactory.decodeFile(config.downloaded_image_path);
                    Log.i("Path",config.downloaded_image_path);
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();  
                    bMap.compress(Bitmap.CompressFormat.PNG, 100, baos); //bm is the bitmap object   
                    byte[] b = baos.toByteArray(); 
                    params.putByteArray("photo", b);
                } catch  (Exception e) {
                    e.printStackTrace();
                }
                params.putString("caption", config.facebook_comment);
                Utility.mAsyncRunner.request("me/photos", params, "POST", new PhotoUploadListener(), null);

Try changing the keyvalue for param as "photo" instead of "picture" and in the request method you are providing null for GRaphApi which is certainly wrong.

故人爱我别走 2025-01-12 03:06:42

试试这个 FB

它可能对你有帮助。

Try this one FB

it may helps you.

睫毛溺水了 2025-01-12 03:06:42

好的,我成功登录了,并发布了这是正确的回复吗...

02-13 14:48:55.949: D/Facebook-Example(2814): Response: {"pid":"100002384000781_493454","aid":"100002384000781_53368","owner":100002384000781,"src":"http:\/\/photos-h.ak.fbcdn.net\/hphotos-ak-ash4\/400189_233648050057993_100002384000781_493454_803419378_s.jpg","src_big":"http:\/\/a8.sphotos.ak.fbcdn.net\/hphotos-ak-ash4\/400189_233648050057993_100002384000781_493454_803419378_n.jpg","src_small":"http:\/\/photos-h.ak.fbcdn.net\/hphotos-ak-ash4\/400189_233648050057993_100002384000781_493454_803419378_t.jpg","link":"http:\/\/www.facebook.com\/photo.php?fbid=233648050057993&set=a.233615786727886.53368.100002384000781&type=1","caption":"","created":1329124670,"object_id":233648050057993}

OK, i managed to log in, and posted is it the right response...

02-13 14:48:55.949: D/Facebook-Example(2814): Response: {"pid":"100002384000781_493454","aid":"100002384000781_53368","owner":100002384000781,"src":"http:\/\/photos-h.ak.fbcdn.net\/hphotos-ak-ash4\/400189_233648050057993_100002384000781_493454_803419378_s.jpg","src_big":"http:\/\/a8.sphotos.ak.fbcdn.net\/hphotos-ak-ash4\/400189_233648050057993_100002384000781_493454_803419378_n.jpg","src_small":"http:\/\/photos-h.ak.fbcdn.net\/hphotos-ak-ash4\/400189_233648050057993_100002384000781_493454_803419378_t.jpg","link":"http:\/\/www.facebook.com\/photo.php?fbid=233648050057993&set=a.233615786727886.53368.100002384000781&type=1","caption":"","created":1329124670,"object_id":233648050057993}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文