M
M
Mark Adams2016-03-06 22:59:46
Python
Mark Adams, 2016-03-06 22:59:46

How to properly collect data from Instagram API and Foursquare API?

I need to collect the maximum number of check-ins for a specific city from Foursquare and do the same with Instagram.
The problem is that in addition to the request limits (per hour), the API returns 10-20 results for any request, even if I change the request parameters and increase the number of results. I understand that you can’t collect a lot with one request and you need to run the algorithm several times (already for the locations found), but still it gives out very little.
What do i do?
I would be happy with an example of a request for a specific city.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Victor Aubin, 2016-03-08
@nebo_oben

1. Bypass restrictions on one token => you need more tokens, either you fool around and registrate a bunch of accounts in these social networks, or you arm yourself with search engines and search on sites ala pastebin, a link to a search engine for 100+ such resources tyk tyk , there you go to the Documents section - > Custom Pastebins (Meta search). The goal is to find someone's sources from which they forgot to remove the tokens, I once collected about 10 like this, but write yourself a small token checker script in advance, for example:

from requests import get
ig_api_key = 'YOUR INSTAGRAM API KEY'
answer = get('https://api.instagram.com/v1/users/search?q=facebook' + '&access_token=' + ig_api_key, verify=True).json()
print answer

There, respectively, substitute the token found and look at the answer, if everything is fine, then the token is working.
BUT: I am sure that it is forbidden to do this in the ToS Instagram API, therefore, at your own peril and risk.
2. As mentioned above, smoke the docks and read about Pagination, for example, here are two methods that pull out data about the user's photos (carefully the code, but enough for the example).
def get_data_from_json(json_text):
    answer = list()
    for element in json_text['data']:
        answer.append(element)
    return answer


def get_media(username):
    answer = list()
    user_id = get_user_id(username)
    data = get('https://api.instagram.com/v1/users/' + user_id + '/media/recent/?access_token=' +\
               ig_api_key, verify=True).json()
    try:
        if data[u'meta'][u'code'] == 200:
            if data[u'pagination'] == {}:
                answer += get_data_from_json(data)
            else:
                answer += get_data_from_json(data)
                while True:
                    if data[u'pagination'] != {}:
                        data = get(data[u'pagination'][u'next_url'], verify=True).json()
                        answer += get_data_from_json(data)
                    else:
                        break
        else:
            answer = list()
    except:
        answer = list()
    return answer

3. Now about the city, for this you need to know its coordinates (or you can automate it yourself through the Google Maps API, there will be an address -> coordinates), then you come up with an algorithm by which a set of points will be generated from two lat \ long coordinates for a subsequent request to the Instagram API, more specifically, refer to this method , it makes it possible to obtain data by coordinates at a distance of 1 to 5 km, so you just need to cover the city with circles with a radius of 5 km, an article from habr with a similar topic and python code is here here . Dare and good luck!

N
Narrator69, 2016-03-06
@Narrator69

Have you read the documentation? Not? Read.
Maximum Instagram API returns 20 results, then pagination.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question