Get album ID from facebook android SDK? - android

i found this answer:
fetch photos from facebook album in android
but i want to know how to get the ALBUM_ID?? specifically for the "wall photos" album.

Assuming that you have already made a call to the Graph API as the solution to the link in the OP, why not do a simple for loop? My implementation might of course be different from yours, but something like this should do it for you.
for (int i = 0; i < JAAlbums.length(); i++) {
json_data = JAAlbums.getJSONObject(i);
// Log.d("json_data", json_data.toString());
if (json_data.has("name")) {
String getAlbumCoverName = json_data.getString("name");
if (getAlbumCoverName.equals("Wall Photos")) {
String getAlbumID = json_data.getString("id");
}
}
}
This bit of code, in a slightly implementation always does it for me. Hope it helps you.

I got it working thanks to this post: Android - How to upload photo from the SD card to the Facebook wall
this is the code i used:
String wallAlbumID = null;
String response = facebook.request("me/albums");
JSONObject json = Util.parseJson(response);
JSONArray albums = json.getJSONArray("data");
for (int i =0; i < albums.length(); i++) {
JSONObject album = albums.getJSONObject(i);
if (album.getString("type").equalsIgnoreCase("wall")) {
wallAlbumID = album.getString("id");
Log.d("JSON", wallAlbumID);
break;
}
}
I implemented it differently though, but this is the way to go. (Y)

Related

How to add web link url in text view in Android?

I am getting few google drive attachment links. I want to show them in the text view. But they should be appeared like Attachment 1, Attachment 2 - this way.
Attachment 1 will have a web link and attachment 2 will have another. They should be clickable.
I tried this way but it is not working:
mStrAttach = new ArrayList<>();
if(attchment_arr != null)
{
for(int i = 0; i < attchment_arr.length(); i++)
{
try
{
mStrAttach.add(attchment_arr.getString(i));
}
catch (JSONException e)
{
}
}
}
if(mStrAttach.size() > 0)
{
view.attchment.setText("");
for(int k = 0; k< mStrAttach.size(); k++)
{
String devid = mStrAttach.get(k);
Log.d("Testing", "drive id::: "+devid);
SpannableString ss = new SpannableString("Attachment "+""+(k+1));
ss.setSpan(new URLSpan(devid),0,ss.length(),0);
view.attchment.append(ss + "\n");
}
Linkify.addLinks(view.attchment, Linkify.ALL);
}
But it is not coming as a link. I am not able to click the Attachment 1 or 2.
Can someone please help.
Thanks,
Arindam.
You can save your attachement link in TextView Tag,
textview1.setTag(first_link);
textview2.setTag(second_link);
then whenever you want it just use textview1.getTag(), textview2.getTag();

How can I get image url of all the uploaded images from the cloudinary server?

I have successfully uploaded 6 image one by one on Cloudinary. Now I want to get all images URL. How can I get in android mobile client side?
I am using code below.
List<String> imageList = new ArrayList<>();
Map config = ObjectUtils.asMap(
"cloud_name", "shank",
"api_key", "644617911542992",
"api_secret", "oW3bQk8luOT9UlEkRsH21KoQkxY");
Cloudinary cloudinary = new Cloudinary(config);
Api api = cloudinary.api();
JSONObject outerObject = null;
String jsonNext = null;
boolean ifWeHaveMoreResources = true;
while (ifWeHaveMoreResources) {
try {
outerObject = new JSONObject(api.resources(ObjectUtils.asMap("max_results", 10, "next_cursor", jsonNext)));
if (outerObject.has("next_cursor")) {
jsonNext = outerObject.get("next_cursor").toString();
ifWeHaveMoreResources = true;
} else {
ifWeHaveMoreResources = false;
}
JSONArray jsonArray = outerObject.getJSONArray("resources");
for (int i = 0, size = jsonArray.length(); i < size; i++) {
JSONObject objectInArray = jsonArray.getJSONObject(i);
String public_id = objectInArray.get("public_id").toString();
String url = objectInArray.get("secure_url").toString();
imageList.add(url);
}
} catch (Exception e) {
e.printStackTrace();
}
}
But it gives the exception.
java.lang.Exception: Administration API is not supported for mobile applications
Please help me to resolve this issue.
java.lang.Exception: Administration API is not supported for mobile applications
Due to security reasons, Admin API is not available with client SDK like Android.
You should use some kind of proxy server to make this call to Cloudinary (you can use Cloud Functions for Firebase for example)

How to make fast my android app while using json feeds from server

i have generated an app over e-commerce site (magento 2) while i am trying to startup my app it processing very slowly because of many products in my server is there any possible way to speed up my usage of Async task while using JSON feeds.. Please let me for any possible ways
My one of the AsyncTask coding:
private class GetProduct extends AsyncTask<Void, Void, Void> {
#Override
protected void onPreExecute() {
super.onPreExecute();
// Showing progress dialog
dialog_pro = new ProgressDialog(Healthy_Cat.this);
dialog_pro.setMessage("Please wait...");
dialog_pro.setCancelable(false);
dialog_pro.show();
}
#Override
protected Void doInBackground(Void... arg0) {
HttpHandler sh = new HttpHandler();
String jsonStr = sh.makeServiceCall(url);
if (jsonStr != null) {
try {
JSONArray items = new JSONArray(jsonStr);
for (int i = 0; i < items.length(); i++) {
JSONObject c = items.getJSONObject(i);
pro_name = c.getString("name");
String price = c.getString("price");
JSONArray array = c.getJSONArray("custom_attributes");
for (int k = 0; k < array.length(); k++) {
JSONObject jb = array.getJSONObject(k);
String attr = jb.getString("attribute_code");
if (attr.equalsIgnoreCase("special_price")) {
splprice = jb.getString("value");
}
}
String sku = c.getString("sku");
JSONArray media = c.getJSONArray("media_gallery_entries");
for(int k = 0; k < media.length(); k++) {
JSONObject jb = media.getJSONObject(k);
String imageURL = BaseURL_Helper.MediaBase +jb.getString("file");
media_image = imageURL;
// tmp hash map for single contact
Beanclass dataSet = new Beanclass();
dataSet.setTitle(pro_name);
dataSet.setImage(imageURL);
dataSet.setPrice(price);
dataSet.setSPLPrice(splprice);
dataSet.setSku(sku);
list.add(dataSet);
BeanclassList data = new BeanclassList();
data.setTitle(pro_name);
data.setImage(imageURL);
data.setSku(sku);
data.setSPLPrice(splprice);
data.setPrice(price);
listbean.add(data);
}
}
}catch (final JSONException e) {
runOnUiThread(new Runnable() {
#Override
public void run() {
no_list.setVisibility(View.VISIBLE);
}
});
}
} else {
runOnUiThread(new Runnable() {
#Override
public void run() {
Toast.makeText(getApplicationContext(),
"May be Network error!!",
Toast.LENGTH_LONG)
.show();
}
});
}
return null;
}
#Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
// Dismiss the progress dialog
/**
* Updating parsed JSON data into ListView
* */
if (dialog_pro.isShowing())
dialog_pro.dismiss();
mAdapter = new GridviewAdapter(Healthy_Cat.this,list);
gridlist.setAdapter(mAdapter);
Listadapter = new ListviewAdapter(Healthy_Cat.this,listbean);
listview_pro.setAdapter(Listadapter);
}
}
Thank u in advance..
There are few things you need to update in your code
API Calling lib: I'm using Retrofit for api calling very fast & simple to use. Support Header & Response caching too.
JSON Parsing: You are parsing JSON manually which is a time-consuming process. I'm using Google's JSON parsing Lib Gson. really very fast.
Pagination: If you having lots of data on the server then try to fetch data in small no of pieces. For example in case of "Item Listing API" try to fetch data from the server for 10-15 item at a time rather all the item at a once.
Asyntask performance speed is too low compare to Retrofit.
So For e-commerce app, You must use Retrofit.
There are a few things you can do. For starters, you don't have to parse the whole json, before updating view.
But really you yourself state the issue, which is you have too much data. This is not only a programming issue, it is also a user experience issue, too much data is confusing, especially on a mobile device.
What I suggest is breaking down your data into categories or the like. When app starts, download just a list of categories to display. Upon user choosing a category, then you download the data for that category.
When you download data, do it in chunks, so that you can start displaying right away.
There are many similar ideas that you can implement, for a better user experience.

Inserting data of SQLite into MySql Database

I have an ordering app, I am using SQLite to store what the user has added to it's cart. My problem is that how would I be able to upload all the data in the SQLite database to the server.
So for say, when the user presses the ORDER button, it will upload all the data in the SQLite to the databse.
I am doing this so that the person who will be delivering can retrieve and view the order details of the user, but I am just baffled and stuck on how would I be able to approach or do this.
If anyone has any insight or links that could give me an idea, or maybe provide me an alternative approach it would be great. Thanks in advance everybody! :D
WELL I SOLVED MY PROBLEM and this is my Solution for anyone who needs it!
Cursor data = db.getCartItems();
TotalOrderArray = new JSONArray();
data.moveToFirst();
while(data.isAfterLast() == false)
{
int totalColumn = data.getColumnCount();
TotalOrderObject = new JSONObject();
for (int i = 0; i < totalColumn; i++)
{
try {
TotalOrderObject.put(data.getColumnName(i), data.getString(i));
} catch (JSONException e) {
e.printStackTrace();
}
}
TotalOrderArray.put(TotalOrderObject);
data.moveToNext();
}
data.close();
it gets all of the data in the SQLite database as JSON and then I just upload it to the server. Thanks to everyone who helped!
Step 1: Just fetch the data from SQLite database.
Step 2: Encode this data to JSON format.
eg:-
ArrayList<Product_bean > all_product_list = db.getAllProductInCart(cart_id); // here get the products
JSONArray jarray = new JSONArray();
JSONObject product;
for(Product_bean bean : all_product_list){
product = new JSONObject();
product.put("product_id",bean.getP_id());
......
}
jarray.put(product);
jarray is your request jSON.
Step 3: Send the JSON to your Http... url.

Read random status from a page using facebook api

I am creating an android app for my facebook page. The app is supposed to display random statuses(not just the recent ones) from the facebook page. Is there anyway I could do this?
I haven't done anything of that kind ever, but I think you can gran some logic from this and get it to work.
Step 1:
Make a call to the Facebook API, get all Status Updates and in a for loop, add them to an ArrayList<String>. For example, Facebook returns its data in JSON format. I am assuming, you already know how to fetch data. You need to parse the "message" tag from the JSON data returned by your Facebook API call.
For example:
ArrayList<String> arrStatusMessage;
for (int i = 0; i < JAFeeds.length(); i++) {
JSONObject JOFeeds = JAFeeds.getJSONObject(i);
if (JOFeeds.has("message")) {
String strStatusMessage = JOFeeds.getString("message");
arrStatusMessage.add(strStatusMessage );
}
}
Step 2:
Once you have your entire set of Facebook Status Messages, you will now need to use a java.util.Random instance.
For example: (Please note: I have not tested this code and it might result in errors. You may have to play around with it a bit to get it to work. :-( )
private static final Random randomGenerator = new Random();
int intRandom = randomGenerator.nextInt(arrStatusMessage.size());
String strRandomStatus = arrStatusMessage.get(intRandom);
Step 3:
Use the strRandomStatus to set it on a TextView.
For example:
TextView txtRanStatus = (TextView) findViewById(R.id.txtRanStatus);
txtRanStatus.setText(strRandomStatus);
You haven't posted any code, so it is difficult to provide something that fits in your scheme of things. But I think this should get you started. You will, possibly, need to adapt a few things and fit them in your own code.
Hope this helps.
EDIT: As per a comment by th OP, adding some bits of code to fetch Facebook Status Messages:
in your onCreate() method:
Start a new AsyncTask:
new getFacebookFeeds().execute();
I use this method in my app to make the Facebook Call to get all feeds from the Graph API.
private class getFacebookFeeds extends AsyncTask<Void, Void, Void> {
#Override
protected Void doInBackground(Void... params) {
String URL = "https://graph.facebook.com/me/home&access_token=ACCESS_TOKEN?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 result = EntityUtils.toString(rp.getEntity());
// GET THE INTIAL RESULTS JSON ROOT
JSONObject JORoot = new JSONObject(result);
// GET THE "DATA" TAG FOR FEEDS ROOT
JSONArray JAFeeds = JORoot.getJSONArray("data");
for (int i = 0; i < JAFeeds.length(); i++) {
JSONObject JOFeeds = JAFeeds.getJSONObject(i);
if (JOFeeds.has("message")) {
String strStatusMessage = JOFeeds.getString("message");
arrStatusMessage.add(strStatusMessage );
}
}
}
} catch (Exception e) {
// TODO: handle exception
}
}
}
You can do the remaining code, where you select a random Status Update, in the onPostExecute() of the AsyncTask shown above:
#Override
protected void onPostExecute(Void result) {
int intRandom = randomGenerator.nextInt(arrStatusMessage.size());
String strRandomStatus = arrStatusMessage.get(intRandom);
txtRanStatus.setText(strRandomStatus);
}
Declare the TextView as a Global Variable and cast it on your onCreate() before calling the AsyncTask. I think this should work just fine. Let me know how it goes. :-)

Categories

Resources