4

我认为标题是自我描述的。在我的应用程序中,我有一个登录表单。根据要求,用户应该能够通过 Facebook 设置他们的个人资料图像。

所以,我的问题是,是否可以在应用程序内显示用户的图库图像并让用户从中选择图像?

我已经检查了Facebook SDK并进行了检查,但我发现的这些信息是基于通过 Graph 将图像上传到 Facebook。

任何建议/意见将不胜感激。

4

1 回答 1

0

您是否在这里检查过这个答案:

ImageView user_picture;
 userpicture=(ImageView)findViewById(R.id.userpicture);
 URL img_value = null;
 img_value = new URL("http://graph.facebook.com/"+id+"/picture?type=large");
 Bitmap mIcon1 = BitmapFactory.decodeStream(img_value.openConnection().getInputStream());
 userpicture.setImageBitmap(mIcon1);

您也可能会看到一点。

编辑:

我认为这应该可以加载专辑,但唯一的区别是你需要一个access token。这意味着只有当这个用户登录到 Facebook 时,你才能获取用户的专辑。下面的代码有一个AsyncTask被调用的getAlbumsData。在里面查看doInBackground.它获取JSON,然后onPostExecute你会看到它正在将专辑加载到之前已经定义的列表视图中。

这是(简单)示例代码

private class getAlbumsData extends AsyncTask<Void, Void, Void> {

    LinearLayout linlaHeaderProgress = (LinearLayout) findViewById(R.id.linlaHeaderProgress);

    @Override
    protected void onPreExecute() {

        // SHOW THE PROGRESS BAR (SPINNER) WHILE LOADING ALBUMS
        linlaHeaderProgress.setVisibility(View.VISIBLE);
    }

    @Override
    protected Void doInBackground(Void... params) {

        // CHANGE THE LOADING MORE STATUS TO PREVENT DUPLICATE CALLS FOR
        // MORE DATA WHILE LOADING A BATCH
        loadingMore = true;

        // SET THE INITIAL URL TO GET THE FIRST LOT OF ALBUMS
        URL = "https://graph.facebook.com/" + initialUserID
                + "/albums&access_token="
                + Utility.mFacebook.getAccessToken() + "?limit=10";

        try {

            HttpClient hc = new DefaultHttpClient();
            HttpGet get = new HttpGet(URL);
            HttpResponse rp = hc.execute(get);

            if (rp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                String queryAlbums = EntityUtils.toString(rp.getEntity());

                JSONObject JOTemp = new JSONObject(queryAlbums);

                JSONArray JAAlbums = JOTemp.getJSONArray("data");

                if (JAAlbums.length() == 0) {
                    stopLoadingData = true;
                    Runnable run = new Runnable() {

                        @Override
                        public void run() {
                            Toast.makeText(getApplicationContext(),
                                    "No more Albums", Toast.LENGTH_SHORT)
                                    .show();
                        }
                    };
                    Albums.this.runOnUiThread(run);

                } else {
                    // PAGING JSONOBJECT
                    if (JOTemp.has("paging"))   {
                        JSONObject JOPaging = JOTemp.getJSONObject("paging");

                        if (JOPaging.has("next")) {
                            String initialpagingURL = JOPaging
                                    .getString("next");

                            String[] parts = initialpagingURL.split("limit=10");
                            String getLimit = parts[1];

                            pagingURL = "https://graph.facebook.com/"
                                    + initialUserID + "/albums&access_token="
                                    + Utility.mFacebook.getAccessToken()
                                    + "?limit=10" + getLimit;

                        } else {
                            stopLoadingData = true;
                            Runnable run = new Runnable() {

                                @Override
                                public void run() {
                                    Toast.makeText(getApplicationContext(),
                                            "No more Albums",
                                            Toast.LENGTH_SHORT).show();
                                }
                            };
                            Albums.this.runOnUiThread(run);
                        }
                    } else {
                        stopLoadingData = true;
                        Runnable run = new Runnable() {

                            @Override
                            public void run() {
                                Toast.makeText(getApplicationContext(),
                                        "No more Albums",
                                        Toast.LENGTH_SHORT).show();
                            }
                        };
                        Albums.this.runOnUiThread(run);

                    }

                    getAlbums albums;

                    for (int i = 0; i < JAAlbums.length(); i++) {
                        JSONObject JOAlbums = JAAlbums.getJSONObject(i);

                        if (JOAlbums.has("link")) {

                            albums = new getAlbums();

                            // GET THE ALBUM ID
                            if (JOAlbums.has("id")) {
                                albums.setAlbumID(JOAlbums.getString("id"));
                            } else {
                                albums.setAlbumID(null);
                            }

                            // GET THE ALBUM NAME
                            if (JOAlbums.has("name")) {
                                albums.setAlbumName(JOAlbums
                                        .getString("name"));
                            } else {
                                albums.setAlbumName(null);
                            }

                            // GET THE ALBUM COVER PHOTO
                            if (JOAlbums.has("cover_photo")) {
                                albums.setAlbumCover("https://graph.facebook.com/"
                                        + JOAlbums.getString("cover_photo")
                                        + "/picture?type=normal"
                                        + "&access_token="
                                        + Utility.mFacebook
                                                .getAccessToken());
                            } else {
                                albums.setAlbumCover("https://graph.facebook.com/"
                                        + JOAlbums.getString("id")
                                        + "/picture?type=album"
                                        + "&access_token="
                                        + Utility.mFacebook
                                                .getAccessToken());
                            }

                            // GET THE ALBUM'S PHOTO COUNT
                            if (JOAlbums.has("count")) {
                                albums.setAlbumPhotoCount(JOAlbums
                                        .getString("count"));
                            } else {
                                albums.setAlbumPhotoCount("0");
                            }

                            arrAlbums.add(albums);
                        }
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }

    @Override
    protected void onPostExecute(Void result) {

        // SET THE ADAPTER TO THE LISTVIEW
        lv.setAdapter(adapter);

        // CHANGE THE LOADING MORE STATUS
        loadingMore = false;

        // HIDE THE PROGRESS BAR (SPINNER) AFTER LOADING ALBUMS
        linlaHeaderProgress.setVisibility(View.GONE);
    }

}

如需更多帮助,请查看原始答案。如果仍然需要,则需要更多完整的工作源代码和解释。虽然这比我提到的答案更令人困惑。Inshallah,这将解决您的查询。

于 2013-03-06T04:35:01.053 回答