I've been using String(contentsOfURL: NSURL) to retrieve the HTML file of a website (a post on Instagram like this one https://instagram.com/p/5FcnSATPa4/ in my case). I need some information about the post like how many likes the post has received or the location associated with the photo.
This line of the HTML file, for example, contains some of the info I need \"location\":{\"has_public_page\":true,\"name\":\"Kaputa\\u015f Beach\". The question is: how can I extract that "Kaputa Beach" name?
Thank you.
Why not use the actual Instagram API? https://instagram.com/developer/endpoints/likes/
Why spend time parsing the HTML when you get that information straight from the source.
You can authorise using OAuth (https://github.com/dongri/OAuthSwift)
You could retrieve a list of users who have liked an image using the call below, you can then derive the 'like' count from this:
https://api.instagram.com/v1/media/{media-id}/likes?access_token=ACCESS-TOKEN
Alternatively if you want more information on the media, you can use the following endpoint:
https://api.instagram.com/v1/media/{media-id}?access_token=ACCESS-TOKEN
Details here: https://instagram.com/developer/endpoints/media/#get_media
Here is an example of a swift app using the Instagram API, you can check out the project on GitHub to see how it works.
https://maniacdev.com/2015/01/example-a-swift-based-ios-instagram-photo-downloader-and-browser
EDIT:
You don't need to authenticate as a particular user to use the methods you need.
Login to instagram as yourself:
https://instagram.com/accounts/login/
Register a new client: https://instagram.com/developer/clients/manage/
Use your new client id with requests instead of your access token:
https://api.instagram.com/v1/media/{media-id}/likes?client_id={CLIENT_ID}
or
https://api.instagram.com/v1/media/shortcode/5FcnSATPa4?client_id={CLIENT_ID}
You can make up to 5000 requests per hour with your client id.
You can play around with the Instagram API here: https://apigee.com/console/instagram
Just remember to use your client id.
Related
for a master thesis I need to analyze several Instagram profiles with more than 1000 posts each.
I need a list of the following things:
Post Type (Image, Multi Image, Video)
description
Likes
Comments (count)
Is there a way to do this with the Instagram Api or do you have another idea how this can work?
Thank you so much
Torben
Sorry. Not easily possible. Facebook has disabled this feature. What parts of this that still work will likely be disabled. You could try to scrape the profiles yourself from the public HTML Instagram webpages.
Using the developer console in Google Chrome and analyzing the network traffic I found the following URL that might be able to do some of what you want. Looks like calling the /graphql/query/ URL with a JSON object as a query parameter labeled: variables, along with a hash of some kind of that object. Not sure if you can call it on your own, but I've had success with other embedded URLs like this. The ID is the users ID which you can get from the HTML as well.
I hope it helps somehow.
https://www.instagram.com/graphql/query/?query_hash=76d9c5f9c2d88aa251ece9ea61fdc570&variables=%7B%22id%22%3A%225466275%22%2C%22first%22%3A12%2C%22after%22%3A%22AQCqBkaT0gZcgV1z9nfTgM3saTJi3cDRQoQy2YM4SdWNWyo3kdMTfCzWvuGcGRI9e1WpAIquMMG9jeuuXSe0TSMiQMPIL1ZmVimTMQ0dfrD_9Q%22%7D
Decoded that is:
https://www.instagram.com/graphql/query/?query_hash=76d9c5f9c2d88aa251ece9ea61fdc570&variables={"id":"5466275","first":12,"after":"AQCNhv_lxGd-nHBBaZb5kk3J4N-n058NgyCiWDnJ10rLc2V-YrVUvGsiuXr4NsMQ4QDzOLdjbTIVqoMpspJ69r-0s-PzOceis9J25o8P2BcjdA"}
I'm very new to the api system and i was wondering how to get data from a certain page. So my link is:
https://nookipedia.com/w/api.php
but i want to get my api from this page:
https://nookipedia.com/wiki/Bugs/Animal_Crossing:_New_Leaf
but when i try this:
https://nookipedia.com/wiki/Bugs/Animal_Crossing:_New_Leaf/w/api.php
the link doesn't work and gives me this error:
Error 404: Not found
The requested page or file could not be found on our server. It may have been moved or deleted.
How would i get that certain page?
I suggest you play around with the API sandbox on Wikipedia to see how queries are built. You will still need to read the actual API documentation to get useful information...
Basically, you want to pass the title(s) as a parameter to api.php, like so:
https://nookipedia.com/w/api.php?titles=Bugs/Animal_Crossing:_New_Leaf
However, this will still get you no information by itself; you need to know what data you want exactly, and use the correct API module with the appropriate parameters. For example, to get all the categories of a page:
https://nookipedia.com/w/api.php?action=query&titles=Bugs/Animal_Crossing:_New_Leaf&prop=categories
For this specific example, you can see the documentation for the Query API and the Categories property:
API:Query
API:Categories
I'm new with Canvas lms and just wondering if anyone know how to get the user info and course id. need some examples
Below is the link I found, but still can't figure out how to use this in my php to grab the user info.
https://canvas.instructure.com/doc/api/file.object_ids.html
Thanks in advance.
Suppose you have the OAuth2 ACCESS-TOKEN and your USER-ID, you can simply use HTTP GET requests to obtain this information.
In order to get your user info, you need to perform a GET request to the following URL:
https://canvas.instructure.com/api/v1/users/<USER-ID>/profile?access_token=<ACCESS-TOKEN>
In order to get course id for the list of courses you belong to, you need to perform a GET request to the following URL: https://canvas.instructure.com/api/v1/courses?access_token=<ACCESS-TOKEN>
For more capabilities you can use the following API documentation:
https://canvas.instructure.com/doc/api/index.html
I am doing an analysis of Credit Union social activity. I have some code that takes a link like this...
https://www.facebook.com/americanlakecu/likes
... and converts it to this...
http://graph.facebook.com/americanlakecu
..which enables me to grab 'Likes' and 'People Talking'. The problem is many institutions, particularly the smaller ones, seem to use a different format. Here's an example.
https://www.facebook.com/pages/EvergreenDIRECT-Credit-Union/276887662722?sk=likes
Anyone know how to convert the link above so I can use the api to render JASON in the same way as http://graph.facebook.com/americanlakecu ?
You need to reference the facebook id when hitting the graph for the other institutions. For americanlakecu, that id is americanlakecu. For Evergreen's case, try 276887662722. But for some reason, your "smaller" pages need an access token. I think the difference might be a simple matter of availability of data.
You can still get their data as I described above, but you need an api access token. For instance, following this link directly will show you nothing: http://developers.facebook.com/tools/explorer/?method=GET&path=276887662722 , but after you get there, if you fetch an access token, you will see all the info you need.
So, configure your implementation of the SDK to use an access token, and you ought to be able to continue using the handy graph method.
I'm learning how to use a third party API called Wunderground and I don't know how to request, receive, and use their results which is in a Json format.
If you see their website a developer can sign up for free and receives an API KEY. You can then request weather data in the following URL format.. http://api.wunderground.com/api/KEY/FEATURE/[FEATUREā¦]/[SETTINGā¦]/q/QUERY.FORMAT
So I have tried it in my web browser by typing some parameters and I received a very long Json file with the correct information (I checked). Problem is I don't have the slightest idea of how to create a variable which can make this request, and even if I was able to do that I don't know where should I receive the file and how to get only the results I want (in this case current weather).
You have to use Titanium.Network.HTTPClient to make request.
For code examples related to Json parsing you can use:
Appcelerator: Using JSON to Build a Twitter Client
HTTPClient()