Thumnails for images in Instagram Graph API - facebook-graph-api

I'd like to ask if there is any way to get thumbnail image for media returned from Instagram Graph API? I can get an image URL by using following endpoint: /{InstagramUserId}/media?fields=media_url
However it only returns one size. Old Instagram API returned various sizes like low_resolution, thumbnail, standard_size. Is it possible to get similar result by using Instagram Grahp API?

After searching for some time to a solution i finally found one.
So, include in the fields query string the permalink field and it should give as following (Sorry, for using Kim Kardashian as an example):
https://www.instagram.com/p/CAYDz52gSLh
then append this at the end media?size=t or simply media like this:
https://www.instagram.com/p/CAYDz52gSLh/media?size=t
media?size=t will give a 150x150 px image
media?size=m will give a 320x320 px image
media?size=l will give a 1080x1080 px image

I can not find a way to get the thumbnails in one step.
But in the next step after receiving the data, the thumbnail of each image and video can be found in this way using oEmbed:
https://graph.facebook.com/v9.0/instagram_oembed?url={permalink}&maxwidth=320&fields=thumbnail_url,author_name,provider_name,provider_url&access_token={accessToken}
permalink: The url received from the previous stage (business_discovery)
Example:
https://graph.facebook.com/v9.0/instagram_oembed?url=https://www.instagram.com/p/CBOuPY1AcMQ/&maxwidth=320&fields=thumbnail_url,author_name,provider_name,provider_url&access_token={accessToken}
More Details

Related

Vision API : Difference in results from drag drop and java vision api client

I have the attached image as shown in the bottom of this question.
I go to drag and drop: https://cloud.google.com/vision/docs/drag-and-drop
Upload this image on above link and go to Web. I see 50 links under "Pages with Matched Images"
Now I run the vision API client in Java
for (WebPage page : annotation.getPagesWithMatchingImagesList()) {
String url = page.getUrl();
System.out.println(url);
}
The result of above code is only 10 links.
http://www.clubic.com/connexion-internet/fai-sfr-box-neufbox/actualite-755413-probleme-technique-sfr-pu-prevenir.html
https://www.nextinpact.com/news/93154-option-tv-obligatoire-l-information-clients-sfr-a-souffert-d-un-probleme-technique.htm
https://www.macg.co/ailleurs/2015/02/sfr-facture-son-option-tv-obligatoire-sans-prevenir-87427
https://play.google.com/store/apps/details?id=cat.gencat.mobi.vacunes&hl=en
http://pressmans.com/index.php/probleme-sfr-tv-ugg01
https://play.google.com/store/apps/details?id=com.moddity.marketing4ecommerce&hl=en
https://support.shopo.in/hc/en-us/articles/209451025-How-to-get-orders-
https://play.google.com/store/apps/details?id=ru.kontinent.protection&hl=en
https://play.google.com/store/apps/details?id=appinventor.ai_fendy3d.Phone_Jammer&hl=en
http://www.media.mts.ru/technologies/124104/
Why is this mismatch. Is it normal or am I missing something.
I am not sure how exactly looks your http request.
But make sure you read the API docs for that maxResults parameter. This can be the cause for so few results.

django sorl-thumbnail inverse function of get_thumbnail()

I'm trying to set up permission checking to static files uploaded by users. To do this, I use the path requested to get the media object which represents the file. I also use sorl-thumbnail library to make thumbnails. I use get_thumbnail() function to get the cached thumbnail from an url of the original uploaded picture. Is there any way of doing the inverse operation? from a cached image url, can i have the original url? something like:
picture = Image.objects.get(url=get_original('/cached/url/of/the/thumbnail/image'))
There is no default way to do this. Sorl thumbnail generates the path for the new thumbnail by creating a hash of the original file name along with the options you have specified so there is no easy way to reverse that operation. You could create a DB table the maps the original image file to your current thumbnail and keeps it up to date everytime the dimensions etc. change.

How to access counters of 'shares' with a Facebook OG object ?

I have a facebook app, with an page whith its meta og tags. When I run http://graph.facebook.com/ID_Object, I get a json file with no entry for share-count but the page was shared several times. How to do that ?
Try calling the url by id.
https://graph.facebook.com/?id=YourURL
refer to: https://developers.facebook.com/docs/reference/api/#auth
You can also request multiple objects in a single query using the
"ids" query parameter. For example, the URL
https://graph.facebook.com?ids=arjun,vernal returns both profiles in
the same response.
The "ids" query parameter also accepts URLs. This is useful for
finding IDs of URLs in the Open Graph. For example:
https://graph.facebook.com/?ids=http://www.imdb.com/title/tt0117500/
The Open Graph protocol defines four required properties:
og:title - The title of your object as it should appear within the graph, e.g., "The Rock".
og:type - The type of your object, e.g., "movie". See the complete list of supported types.
og:image - An image URL which should represent your object within the graph. The image must be at least 50px by 50px (though minimum 200px by 200px is preferred) and have a maximum aspect ratio of 3:1. We support PNG, JPEG and GIF formats. You may include multiple og:image tags to associate multiple images with your page.
og:url - The canonical URL of your object that will be used as its permanent ID in the graph, e.g., http://www.imdb.com/title/tt0117500/.

How to get the extra large cover image from google book API?

According to Google doc, using this link can get the URL extra large for a book
Google doc
However, when I clicked https://www.googleapis.com/books/v1/volumes/zyTCAlFPjgYC , there are only 2 thumbnails (small and medium). So do I need to obtain a Google API key to get full information about a book ?
I figured out that you can replace the &zoom=1 part of the URL with &zoom=0 for larger images, but only in some cases.
For an example, this is the Sherlock Holmes small thumbnail:
http://bks5.books.google.com/books?id=buc0AAAAMAAJ&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api
Now, by setting zoom to 0, I get a large thumbnail:
http://bks5.books.google.com/books?id=buc0AAAAMAAJ&printsec=frontcover&img=1&zoom=0&edge=curl&source=gbs_api
Actually with some books, google provides large image but some not.
set the zoom to 3 instead of 0 or 1 and it should work
Just change zoom size in url.
let img = "https://books.google.com/books/content?id=54BEAAAACAAJ&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api"
let imgZoom = img.replace('zoom=1', 'zoom=10')
newImg.src= imgZoom;
<img src="" id="newImg">

Plot a graph in the html file using Django

I am doing a monitoring system using Django. In my views file, I have defined one class called showImage which collects the information necessary to plot a graph using matplotlib.
At the beginning, I just stored the image in a string buffer to represent it with HttpResponse:
buffer = StringIO.StringIO()
canvas = pylab.get_current_fig_manager().canvas
canvas.draw()
pilImage = PIL.Image.fromstring("RGB", canvas.get_width_height(), canvas.tostring_rgb())
pilImage.save(buffer, "PNG")
# Send buffer in a http response the the browser with the mime type image/png set
return HttpResponse(buffer.getvalue(), mimetype="image/png")
However, I need to implement some javaScript in the html file to add more applications. For that reason, I have decided to save the image in a variable and plot it in the html file:
# serialize to HTTP response
response = HttpResponse(buffer.getvalue(), mimetype="image/png")
return render_to_response('eQL/dev/showImage.html', {'response':response})
My question is that I don't really know how to represent it in the html file because I didn't find any example doing it. Any one knows the answer?
Thanks in advance!
Do you mean that in your first implementation, your response was a PNG file, but now you wish to make the response an HTML file instead, containing the image?
Well firstly, you need to change the response MIME type from image/png to text/html or similar.
Secondly, I'm not sure why you are passing a HttpResponse object (containing the PNG data) into the template. Can the template even read that? Surely you just want to be passing the raw PNG data, not a HttpResponse object.
Finally, how to do it. Well as you may know, HTML isn't so great at embedding images. As with normal websites, you can include text in the page, but if you want an image, you need a separate file and link to it using the <img src="..." /> element. This is tricky to do dynamically: it means you need to setup two separate URLs (one for the PNG and one for the HTML), which run independently of one another (you can't just have one piece of code; you need one handler for generating the PNG and the other for generating the HTML), and have the HTML link to the PNG URL.
If that is too hard, there is another way out, but it is a bit hacky: data URLs. They let you include image data in the HTML page itself, so you only need to produce one response. Unfortunately it is not well supported in Internet Explorer pre-9. IE8 supports images less than 32K, IE7 and below don't work. See the example on Wikipedia -- you are aiming to generate something like this:
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA
AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot" />
Basically, take the PNG data, and Base64-encode it (use Python's base64 library). Then just put "data:image/png;base64," in front of it, and set that as the URL for the img src. In other words, pass the Base64-encoded string to Django's template engine, and construct the URL as part of the img tag in the template.