Snippets

Terah FacebookPageImageWrapper

Created by Terah last modified
abstract class FacebookPageImageWrapper {
		/*
		 * This is the class that will take care of getting the page
		 * with image etc etc.
		 * 
		 */

		/**
		 * 
		 * @param pageID
		 * 
		 * THis is your page id. Page who's images you want
		 */

		private String PageID = "",
				/**
				 * 
				 * @param AppID
				 * 
				 * This is your appid you created on fb
				 */				
				AppID = "",
				/**
				 * 
				 * @param AppSecret
				 * 
				 * Your secret.
				 */
				AppSecret = "";
		private ArrayList<Bitmap> pics_B;
		private ArrayList<Drawable> pics_D;

		private String profilePicUrl = "";

		public FacebookPageImageWrapper(String pageID, String appID, String appSecret) {
			PageID = pageID;	
			this.AppID = appID;
			this.AppSecret = appSecret;
			new Thread(new Runnable() {

				@Override
				public void run() {
					pics_B = new ArrayList<Bitmap>();
					try {						

						String url = IOUtils.toString(new URL("https://graph.facebook.com/" +
								PageID +
								"?fields=picture").openStream());
						JSONObject json = new JSONObject(url);
						json = json.getJSONObject("picture");
						json = json.getJSONObject("data");
						profilePicUrl = json.getString("url");
						url = IOUtils.toString(new URL("https://graph.facebook.com/" +
								PageID +
								"?fields=photos&access_token=" +
								AppID +
								"|" +
								AppSecret).openStream());
						JSONArray jsona = new JSONObject(url).getJSONObject("photos").getJSONArray("data");
						for(int i =0; i < jsona.length(); i++){
							url = IOUtils.toString(new URL("https://graph.facebook.com/" +
									jsona.getJSONObject(i).getString("id") +
									"?fields=images&access_token=" +
									AppID +
									"|" +
									AppSecret).openStream());
							String Link = new JSONObject(url).getJSONArray("images")
									.getJSONObject(0).getString("source");				

							Log.v("link", Link);
							pics_B.add(BitmapFactory.decodeStream(
									new URL(Link).openStream()));
						}
						PagePictures_B(new ArrayList<Bitmap>(pics_B));

						PageProfilePicture(BitmapFactory.decodeStream(
								new URL(profilePicUrl).openStream()));
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}).start();
		}	

		public abstract void PageProfilePicture(Bitmap bitmap);
		public abstract void PagePictures_B(ArrayList<Bitmap> photos);		

		public ArrayList<Bitmap> getPagePictures_B(){
			return pics_B;
		}

	}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.