我認爲標題是自我描述。在我的應用程序中,我有一個登錄表單。根據請求,用戶應該能夠通過Facebook設置他們的個人資料圖像。是否可以訪問Facebook圖庫並讓用戶選擇圖像?
所以,我的問題是,是否有可能在應用程序內顯示用戶的圖庫圖像,並讓用戶從中選擇圖像?
我檢查了Facebook SDK和goggled以及我發現的那些信息是基於Graph上傳圖片到Facebook。
任何建議/意見將不勝感激。
我認爲標題是自我描述。在我的應用程序中,我有一個登錄表單。根據請求,用戶應該能夠通過Facebook設置他們的個人資料圖像。是否可以訪問Facebook圖庫並讓用戶選擇圖像?
所以,我的問題是,是否有可能在應用程序內顯示用戶的圖庫圖像,並讓用戶從中選擇圖像?
我檢查了Facebook SDK和goggled以及我發現的那些信息是基於Graph上傳圖片到Facebook。
任何建議/意見將不勝感激。
你檢查這個答案here:
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);
您可能會看到this了。
編輯:
我認爲這將工作負載專輯,但唯一不同的是,你需要一個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);
}
}
如需更多幫助,尋找到original answer。如果是,你需要更多的則那裏有一個完整的working source code與explaination.Though那不是更混亂了一下回答我提到.Inshallah,這將解決您的查詢。
感謝Nezam,但我的問題是如何加載Facebook的照片(庫),然後讓用戶從那裏選擇圖像,而不是如何加載配置文件的圖像。再次感謝。 – Hesam 2013-03-06 06:45:20
你有答案嗎? – Nezam 2013-03-07 04:31:45
看到編輯現在.. – Nezam 2013-03-07 04:45:46