I am currently trying to grab all user information using the Microsoft Graph API and I was wondering if there was a more concise way of also grabbing a users photos to replace what I am currently doing.
I am currently doing the following;
Grab user details by calling https://graph.microsoft.com/beta/users?$expand=manager
NOTE: I am using the beta API as I cannot seem to get the manager data back otherwise.
Iterate over users and then for each user call https://graph.microsoft.com/beta/users/{user_id}/photos
For each photo returned I am then;
Calling https://graph.microsoft.com/beta/users/{user_id}/photos/{photo_id} to get the meta data (e.g. id, height and width). NOTE: I have found the height and width on the initial photos are not always correct whereas they are on this call (so I use this one only for the details)
Calling https://graph.microsoft.com/beta/users/{user_id}/photos/{photo_id}/$value to get the image.
This results in lots of individual API calls on top of the users query;
for every user a call to get array of photos
for every photo one to get the photo metadata
for every photo one to get the photo binary data.
This could quickly get substantial with a large organisation utilizing multiple profile pictures per person for different sizes.
Is there a way of expanding the photo data within the initial users call to avoid having to do all of these additional API calls?
Thanks,
John
Couple of things here John.
Calling GET https://graph.microsoft.com/v1.0/me/photos API is basically a way for you to see what photo sizes are available. You can optimize which size you want, based on your experience - for example if it's a mobile device you might select the smallest (or second smallest size). If it's for a desktop device, you might select the largest size. Requesting GET https://graph.microsoft.com/v1.0/me/photo (note the singular) will get the metadata for the largest available photo. The smaller sizes are scaled versions of the largest photo. In some circumstances, only one size is available. Please see details here. So I'm not sure why you need to get every profile photo size (it's the same photo, but different sizes).
You should take a look at batching to make multiple API calls in one round-trip. Please see this batching topic. NOTE: Batching is still in preview, but will GA soon.
Hope this helps,
Related
I have a webservice that acts as a form of a digital asset manager. Some of our users have THOUSANDS of images stored in their account. We want to give them an iPhone app that lets them access these images. We can use infinite scroll but we would like some form of a table of uicollectionview segmented by dates with a side index list that they can scroll through and jump to. To do that we would need to download ALL of their images into a collectionview, which seems insane.
How do others handle displaying, searching and filtering large volumes of images?
Typically when large amounts of data needs to be downloaded from a web service (or filesystem) the key is not to do it all at once, but to partition it into manageable pieces which you load and unload as needed. There is no one way to do this, but that is the general idea.
To manage this process it can be helpful to download a complete index that describes all the content (like a json list of image urls) without downloading every image or piece of data in the database (but not necessary - this won't work with millions of entries). This allows you to search and navigate through content without requiring huge downloads.
In your question it sounds like your images are grouped somewhat by date ranges. A possible procedure you could explore could be something like:
Download an index of all images with their associated dates and load this into memory. (In the thousands this should be no problem).
images : [
{
url: "http://someurl/image.png",
name: "Great Image!",
date: "12/3/15"
// possibly include more data like search tags...
},..
]
Begin downloading the initial set of images associated with most recent date range and display them as they complete.
When the user selects a new date range or scrolls of the page, show placeholder image tiles in the collection view. Start downloading the new images asynchronously and display them as they arrive.
Unload images from the previous date range from memory. (You could keep a cache in the filesystem).
Repeat as the visible area changes.
On iOS I usually use AFNetworking (Or AlamoFire for Swift) to handle asynchronous network requests.
My fiancé and I are trying to make an info graphic for our wedding. One of the metrics that we thought might be fun would be to show the total number of texts or phone calls that we made to one another on our iPhones. I have searched the reports/bills from our wireless carrier, but I don't think this has the information. We have never deleted the text or call history on our phones and live in a 100% Apple ecosystem. Does anybody have suggestions on how we can find out this information? We're open to having to do a bit of work to get at this information (e.g. taking advantage of an API, scraping the back-up files, etc.) Thanks!
I am creating an offline map app for iPhone (Using MKMapKit). It will have a list of countries. If the user selects a country, all tiles will be downloaded and stored on the iPhone. I will use Open Street Map as the maps provider.
(I have read that bulk downloading is forbidden, but given that tiles for a country is pretty small (≈200MB) and that they will only be downloaded once, at least I don't think it's a problem.)
I think I will be using the template URL #"http://c.tile.openstreetmap.org/{z}/{x}/{y}.png" to downloaded the tiles and then store them. My problem is that I don't know how to determine which tiles belong to which country and therefore to determine which to download.
I found this link in another SO answer, but that only allows you to download .pbf files (which I have no idea what it is) and per continent.
First: If you really want to grab all tiles (at all zoom-levels) you should read the OSM Tile Usage Policy again with care. If you just want to download all the tiles once (for your dev environment) you can use existing downloaders that allow you to select the desired country and download them. This will result in a directory with 1000s of small images and might take some days.
The better way would be to setup your own (desktop or server based) tile rendering chain that gives you full control about styling and doesn't stress the community ressources. Please consult www.switch2osm.org for a detailed tutorial on how to setup a server based rendering stack.
This is a problem. Downloading 200 MB of tiles only once is already questionably because it is not just about the traffic, these tiles have to be rendered first. But if I understood you correctly, with your application every user will download these 200 MB.
Instead you should think about downloading raw data (which PBF is) and either render your own raster tiles as already suggested by MaM, or create a vector map as done by other popular apps, like OsmAnd and Navit.
I am making a game in which I need to integrate Facebook leader-board and facebook friends invitation like in subway surfer. I used official facebook sdk and got it done. But the approach I am following is not efficient.
My friend invite screen has its own UI so I could not use the default popup comes with facebook SDK.
I fetch all the friends list from graph api It provides me the list of all IDs of users . But I needed to get name and images of friends to show in a scroll list . I am fetching the images from url asynchronously but whenever I try to fetch the image my scroll list hangs up . here is my code
IEnumerator start ()
{
url ="http://profile.ak.fbcdn.net/hprofile-ak-prn2/t5/1116929_100003613987476_290892640_q.jpg";
WWW www = new WWW(url);
yield return www;
var texture = www.texture;
this.gameObject.GetComponent<UITexture>().mainTexture = texture;
}
I am using coroutines, but I dont know why my scroll hang up on scrolling if these are asynchronous ? The code is been taken form here . I have checked Threading but www can not be used in threads. I just want to smooth my scrollview which I made by using NGUI sdk during image fetching.
Problem 1 - How can I make smooth scrolling by asynchronous image download simultaneously.
Problem 2 - I am loading each image into UITexture of NGUI, which I instantiate at run time. But if one have 200 or above friends then my app's memory reach at apex point and eventually app crashes. Is there any other way to load large number of images so that they take reasonable memory .
Scroll is working smoothly during web call on editor but not on device (iOS). Why ?
Please guys help me to smooth my scroll view and memory issue. Any help shall highly be appreciated. Thakks :)
This is a common problem on devices for any list that has more than 50 items that include images. You need to control two things: initializing list items and downloading assets.
You do not need to load everything at once and display them. I would recommend breaking this down into three parts:
1. Store friend list data
Fetch all the user's Facebook friends and store it in a list. This does not include downloading the profile pictures, only the basic information and the URL of their profile picture. We will download the picture at a later step.
2. Pool list items
Don't create more than triple the list items you can display at any given time. While scrolling, you'll simply reuse the ones already created like so:
You should only need to do the third step in that picture only when the user has lifted his finger and the list has enough momentum to continue scrolling. Otherwise you should have enough items loaded in memory to not require this when the user simply drags the list.
When moving a list item either at the end or the beginning (depending on the direction of the scroll) you should load the friend's data. You still do not load profile pictures at this step.
3. Queuing image requests
You can use Unity's OnBecameVisible method to figure out when an item is currently visible. But generally you'll need a manager that keeps track of what items are visible at any given moment.
Every time the scroll list has no momentum and the user is not dragging it, you queue up requests to fetch the images for the items that are currently visible. This should be handled by a different manager that does the following:
Keeps N most recent profile pictures in memory to avoid loading them every time
Checks to see if the image is already downloaded by using LoadFromCacheOrDownload as Roberto suggested.
Makes sure that the item the request was made for is still visible before setting the texture (otherwise it keeps the image in memory)
Of course, this is very high level. There are many things to implement here and in many different ways. But I hope you get the idea.
I was thinking about this when I asked about starting many coroutines at the same time.
Well you just can't load them all at the same time and expect the app to run smoothly, the hardware is just not able to handle this.
You can made a loading screen or something similar where the user will have to wait to see/use the scroller (though I've never seen a game doing this for loading Facebook pictures) or you will have to give up in showing them all at the same time and create a pool of a small number of WWW connections that you can use at the same time, that is, limit the number of images being loaded at the same time, and only start loading a new image when one has finished.
Now one thing that can certainly speed things up - not in the first time that you run it, but subsequent runs - is to use WWW.LoadFromCacheOrDownload() instead of new WWW(). This method will store the pictures that were downloaded in the past and load them instead of redownloading. This is how every Unity game I've ever seen do integration with Facebook.
I’m making a gallery on site. And don’t know what the best solution for it. Need advice.
For my opinion there are two ways of operating with images.
User uploads image. I save it on server only once, only with its original size. And then, when there’s a need of displaying that image on screen I resize it to the necessary size, for example as avatar. So I store only ONE original-sized image and resize it to ANY proper size RIGHT BEFORE displaying.
User uploads image. I save it on server with original size and also make and save several copies (thumbnails-sized), for example, avatar-sized, erc. So that if the image is displayed it’s not resized every time it is displayed, just proper-sized copy taken.
I think that the second way is better. Because there’s no need to spend server strength on resizing images every time. But what if I’ll decide to change design of my site and some dimensions of images on it will be resized too? I’ll get the situation of having lots of images on server that doesn’t fit new design.
All around different forums they explain how to make galleries and every time they say that thumbnail-sized copies are also made and saved. But it looks like it doesn’t make sense if design is changed in time. Please, advise. Language – PHP.
One solution that others have come up with is a mix between the two. So, the user uploads the photo and you save it in its original form on your server. Then, when an avatar is needed, you check to see if you have the avatar saved on disk (maybe user12345_50x50.jpg - where 50x50 is widthxheight). If it does exist, show that image. If not, then use the server to resize/crop whatever, then save that image to disk and serve that to the user. This will allow you to request any size file and serve it as-needed -- taking advantage of caching those that have already been requested [Note that this is a server-side cache, so would apply for all users].
You sort of get the best of both worlds. You don't need to handle all of the image manipulation up front, just as needed. The first time the image is processed, that user will have to wait, but any other request will get the processed file.
One implementation that uses this solution in PHP is phpthumb: http://phpthumb.sourceforge.net/