如何使用Facebook的Andr​​oid SDK中改变Facebook的个人资料图片? [英] how to change the facebook profile picture using facebook android sdk?

查看:128
本文介绍了如何使用Facebook的Andr​​oid SDK中改变Facebook的个人资料图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的英语也不是那么完美,但我想学习,所以我希望你能理解我。我想知道使用Facebook的Andr​​oid SDK中我怎样才能改变Facebook的个人资料照片。即时通讯能够从我的应用程序上传图片到任何专辑,包括我的照片(我用的是下一个code:)

my english is not so perfect but i want to learn, so i hope you can understand me. I wanna know how can i change the facebook profile pic using facebook android sdk. im able to upload pictures from my app to any album, including "Profile Pictures" (i use the next code:)

params=new Bundle();
params.putByteArray("photo", photo);
params.putString("caption", description);
mAsyncRunner.request(idAlbum+"/photos", params,"POST",new RequestListener() {

                    @Override
                    public void onMalformedURLException(MalformedURLException e, Object state) {}
                    @Override
                    public void onIOException(IOException e,Object state) {}
                    @Override
                    public void onFileNotFoundException(FileNotFoundException e, Object state){}
                    @Override
                    public void onFacebookError(FacebookError e,Object state) {}
                    @Override
                    public void onComplete(String response, Object state) {
                        mHandler.post(new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(getApplicationContext(),"Success", Toast.LENGTH_LONG).show();
                            }
                        });
                    }
                }, null);

但我不知道如何上传图像设置为配置文件照片。也许增加了一些code到这一点?我知道,使用Facebook的SDK的PHP的是我问的是更多钞票。另外,我已经看到了苹果的应用程序,做到这一点。然后,我想我可以在Android的做到这一点。某人有什么即时寻找信息?在此先感谢。

but i dont know how to set the uploaded image as the profile pic. maybe adding some code to this? I know that what i ask is posible using facebook sdk for php. also, i have seen an Apple app that do this too. Then, i think i can do it in android. somebody has information about what im looking for? thanks in advance.

推荐答案

好吧,我发现这样做的方式。这是code:

Ok, I found the way to do that. and this is the code:

params=new Bundle();
    try {
        params.putByteArray("photo", photo);
    } catch (IOException e) {
        e.printStackTrace();
    }
    params.putString("caption", description);

mAsyncRunner.request(idAlbum+"/photos", params,"POST",
                        new RequestListener() {
                    @Override
                    public void onMalformedURLException(MalformedURLException
                            e, Object state) {}
                    @Override
                    public void onIOException(IOException e,Object state) {}
                    @Override
                    public void onFileNotFoundException(
                            FileNotFoundException e, Object state){}
                    @Override
                    public void onFacebookError(FacebookError e,Object state) {}

                    @Override
                    public void onComplete(final String response, Object state) {
                        mHandler.post(new Runnable() {
                            @Override
                            public void run() {
                                try {
                                    JSONObject json=new JSONObject(response);
                                    JSONObject obj=new JSONObject(
                                            facebook.request("me"));
                                    final String photoId=json.getString("id");
                                    String userId=obj.getString("id");

                                    String url="https://m.facebook.com/photo." +
                                            "php?fbid="+photoId+"&id="+userId+
                                            "&prof&__user="+userId;
                                    Intent mIntent=new Intent(Intent.ACTION_VIEW,
                                    Uri.parse(url));
                                    startActivity(mIntent);
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                } catch (MalformedURLException e) {
                                    e.printStackTrace();
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }

                            }
                        });
                    }
                }, null);

发表于特定相册的照片,获得PHOTOID用的JSONObject,然后重定向到一个网页,用户可以确认此照片为他/她的个人资料照片。

Post the photo on a specific album, get the photoID with a JSONObject, and then redirect to a web page where the user can confirm to set the photo as his/her profile picture.

这篇关于如何使用Facebook的Andr​​oid SDK中改变Facebook的个人资料图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆