Title: | Access to Instagram API via R |
---|---|
Description: | Provides an interface to the Instagram API <https://instagram.com/ developer/>, which allows R users to download public pictures filtered by hashtag, popularity, user or location, and to access public users' profile data. |
Authors: | Pablo Barbera [aut, cre], Tiago Dantas [ctb], Jonne Guyt [ctb] |
Maintainer: | Pablo Barbera <[email protected]> |
License: | GPL-2 |
Version: | 0.2.5 |
Built: | 2024-11-23 02:46:04 UTC |
Source: | https://github.com/pablobarbera/instar |
getComments
retrieves up to 150 recent comments on an instagram post,
including text, author and date.
getComments(id, token, verbose = TRUE)
getComments(id, token, verbose = TRUE)
id |
String, id of instagram post. |
token |
An OAuth token created with |
verbose |
If |
IMPORTANT: After June 1st, 2016 only applications that have passed permission review by Instagram will be allowed to access data for users other than the authenticated user. See https://www.instagram.com/developer/review/ for more information.
Pablo Barbera [email protected]
## Not run: ## See examples for instaOAuth to know how token was created. ## Downloading list of followers of @senjohnmccain load("my_oauth") obama <- getUserMedia( username="barackobama", token=my_oauth ) comments <- getComments( obama$id[1], token=my_oauth ) ## End(Not run)
## Not run: ## See examples for instaOAuth to know how token was created. ## Downloading list of followers of @senjohnmccain load("my_oauth") obama <- getUserMedia( username="barackobama", token=my_oauth ) comments <- getComments( obama$id[1], token=my_oauth ) ## End(Not run)
getFollowers
retrieves the list of users that follow a given user,
as well as basic information about all of them.
getFollowers(username, token, userid = NULL, verbose = TRUE)
getFollowers(username, token, userid = NULL, verbose = TRUE)
username |
String, screen name of user. |
token |
An OAuth token created with |
userid |
Numeric ID of user. |
verbose |
If |
IMPORTANT: After June 1st, 2016 only applications that have passed permission review by Instagram will be allowed to access data for users other than the authenticated user. See https://www.instagram.com/developer/review/ for more information.
Pablo Barbera [email protected]
## Not run: ## See examples for instaOAuth to know how token was created. ## Downloading list of followers of @senjohnmccain load("my_oauth") mccain <- getFollowers( username="senjohnmccain", token=my_oauth ) ## End(Not run)
## Not run: ## See examples for instaOAuth to know how token was created. ## Downloading list of followers of @senjohnmccain load("my_oauth") mccain <- getFollowers( username="senjohnmccain", token=my_oauth ) ## End(Not run)
getFollows
retrieves the list of users that a given user follows,
as well as basic information about all of them.
getFollows(username, token, userid = NULL, verbose = TRUE)
getFollows(username, token, userid = NULL, verbose = TRUE)
username |
String, screen name of user. |
token |
An OAuth token created with |
userid |
Numeric ID of user. |
verbose |
If |
IMPORTANT: After June 1st, 2016 only applications that have passed permission review by Instagram will be allowed to access data for users other than the authenticated user. See https://www.instagram.com/developer/review/ for more information.
Pablo Barbera [email protected]
## Not run: ## See examples for instaOAuth to know how token was created. ## Downloading list of users that @senjohnmccain follows load("my_oauth") mccain <- getFollows( username="senjohnmccain", token=my_oauth ) ## End(Not run)
## Not run: ## See examples for instaOAuth to know how token was created. ## Downloading list of users that @senjohnmccain follows load("my_oauth") mccain <- getFollows( username="senjohnmccain", token=my_oauth ) ## End(Not run)
getLikes
retrieves the list of users who liked a photo.
getLikes(id, token, verbose = TRUE)
getLikes(id, token, verbose = TRUE)
id |
Numeric ID of photo. |
token |
An OAuth token created with |
verbose |
If |
IMPORTANT: After June 1st, 2016 only applications that have passed permission review by Instagram will be allowed to access data for users other than the authenticated user. See https://www.instagram.com/developer/review/ for more information.
Tiago Dantas [email protected]
## Not run: ## See examples for instaOAuth to know how token was created. ## Downloading list of users who liked @barackobama's most recent photo load("my_oauth") obama <- getUserMedia( username="barackobama", token=my_oauth, n=1) likes <- getLikes(obama$id[1], token=my_oauth) ## End(Not run)
## Not run: ## See examples for instaOAuth to know how token was created. ## Downloading list of users who liked @barackobama's most recent photo load("my_oauth") obama <- getUserMedia( username="barackobama", token=my_oauth, n=1) likes <- getLikes(obama$id[1], token=my_oauth) ## End(Not run)
getLocation
retrieves location information
getLocation(location_id, token)
getLocation(location_id, token)
location_id |
numeric, location id. |
token |
An OAuth token created with |
Jonne Guyt [email protected]
## Not run: ## See examples for instaOAuth to know how token was created. ## Capturing information about a location load("my_oauth") loc_id_info <- getLocation( location_id=423423, token=my_oauth) ## End(Not run)
## Not run: ## See examples for instaOAuth to know how token was created. ## Capturing information about a location load("my_oauth") loc_id_info <- getLocation( location_id=423423, token=my_oauth) ## End(Not run)
getPopular
retrieves up to 24 popular instagram posts
getPopular(token, verbose = TRUE)
getPopular(token, verbose = TRUE)
token |
An OAuth token created with |
verbose |
If |
IMPORTANT: After June 1st, 2016 only applications that have passed permission review by Instagram will be allowed to access data for users other than the authenticated user. See https://www.instagram.com/developer/review/ for more information.
Jonne Guyt [email protected]
## Not run: ## See examples for instaOAuth to know how token was created. ## Downloading list of popular instagram posts load("my_oauth") popular_posts <- getPopular(token=my_oauth ) ## End(Not run)
## Not run: ## See examples for instaOAuth to know how token was created. ## Downloading list of popular instagram posts load("my_oauth") popular_posts <- getPopular(token=my_oauth ) ## End(Not run)
getTagCount
retrieves a count of the number of times a tag has
been used in comments to a picture or video.
getTagCount(tag, token)
getTagCount(tag, token)
tag |
Hashtag used to filter media. |
token |
An OAuth token created with |
Pablo Barbera [email protected]
## Not run: ## See examples for instaOAuth to know how token was created. ## Capturing information about #nofilter load("my_oauth") getTagCount( tag="nofilter", token=my_oauth,) ## End(Not run)
## Not run: ## See examples for instaOAuth to know how token was created. ## Capturing information about #nofilter load("my_oauth") getTagCount( tag="nofilter", token=my_oauth,) ## End(Not run)
getUser
retrieves public information about Instagram user
getUser(username, token, userid = NULL)
getUser(username, token, userid = NULL)
username |
String, screen name of user. |
token |
An OAuth token created with |
userid |
Numeric ID of user. |
IMPORTANT: After June 1st, 2016 only applications that have passed permission review by Instagram will be allowed to access data for users other than the authenticated user. See https://www.instagram.com/developer/review/ for more information.
Pablo Barbera [email protected]
## Not run: ## See examples for instaOAuth to know how token was created. ## Capturing information about @barackobama load("my_oauth") obama <- getUser( username="barackobama", token=my_oauth,) ## End(Not run)
## Not run: ## See examples for instaOAuth to know how token was created. ## Capturing information about @barackobama load("my_oauth") obama <- getUser( username="barackobama", token=my_oauth,) ## End(Not run)
getUserMedia
retrieves public media from a given user and, optionally,
downloads recent pictures to a specified folder.
IMPORTANT: After June 1st, 2016 only applications that have passed permission review by Instagram will be allowed to access data for users other than the authenticated user. See https://www.instagram.com/developer/review/ for more information.
getUserMedia(username, token, n = 30, folder = NULL, userid = NULL, verbose = TRUE)
getUserMedia(username, token, n = 30, folder = NULL, userid = NULL, verbose = TRUE)
username |
String, screen name of user. |
token |
An OAuth token created with |
n |
Maximum number of media to return. Currently it is only possible to download the 20 most recent pictures or videos on the authenticated user's profile, unless Instagram has approved the application. |
folder |
If different than |
userid |
Numeric ID of user. |
verbose |
If |
Pablo Barbera [email protected]
## Not run: ## See examples for instaOAuth to know how token was created. ## Capturing information about 50 most recent pictures by @barackobama load("my_oauth") obama <- getUserMedia( username="barackobama", token=my_oauth, n=50, folder="barackobama") ## End(Not run)
## Not run: ## See examples for instaOAuth to know how token was created. ## Capturing information about 50 most recent pictures by @barackobama load("my_oauth") obama <- getUserMedia( username="barackobama", token=my_oauth, n=50, folder="barackobama") ## End(Not run)
instaOAuth
creates an OAuth access token that enables R to make
authenticated calls to the Instagram API. The token can be saved as a
file in disk to be re-used in future sessions. This function relies on the
httr
package to create the OAuth token, and is a simplified version
of one of its examples.
instaOAuth(app_id, app_secret, scope = c("basic", "public_content"))
instaOAuth(app_id, app_secret, scope = c("basic", "public_content"))
app_id |
numeric, Client ID of application to be used to create OAUth token. Available at http://instagram.com/developer |
app_secret |
string, Client Secret of application to be used to create OAUth token. Available at http://instagram.com/developer. |
scope |
string, specifies scope of access to the authenticated user data. See http://instagram.com/developer/authentication/#scope for available options. |
To obtain your app_id
and app_secret
, do the following steps.
First, go to http://instagram.com/developer/ and register your
application with any name. Then, run the instaOAuth
function with
your "Client ID" and "Client Secret" as arguments. It will return a URL,
which you will need to paste into the field "OAuth redirect_uri" in
your application settings on Instagram. After changing it, press Enter in
R. A new browser window will open and sign the token. If everything works
works well, you will get a message that says you can return to R.
Pablo Barbera [email protected]
## Not run: ## an example of an authenticated request after creating the OAuth token ## where app_id and app_secret are fictitious, and token is saved for ## future sessions my_oauth <- instaOAuth(app_id="123456789", app_secret="1A2B3C4D") save(my_oauth, file="my_oauth") load("my_oauth") obama <- searchInstagram(tag="obama", token=my_oauth) ## End(Not run)
## Not run: ## an example of an authenticated request after creating the OAuth token ## where app_id and app_secret are fictitious, and token is saved for ## future sessions my_oauth <- instaOAuth(app_id="123456789", app_secret="1A2B3C4D") save(my_oauth, file="my_oauth") load("my_oauth") obama <- searchInstagram(tag="obama", token=my_oauth) ## End(Not run)
searchInstagram
retrieves public pictures and video whose caption
mentions a given hashtag, or that were sent within a given area, delimited
by a set of coordinates and a radius. It returns a data frame with
information about each picture or video, and optionally will download
all pictures to a specific folder
searchInstagram(tag = NULL, token, n = 100, lat = NULL, lng = NULL, distance = NULL, folder = NULL, mindate = NULL, maxdate = NULL, verbose = TRUE, sleep = 0)
searchInstagram(tag = NULL, token, n = 100, lat = NULL, lng = NULL, distance = NULL, folder = NULL, mindate = NULL, maxdate = NULL, verbose = TRUE, sleep = 0)
tag |
Hashtag used to filter media. It is only possible for a single hashtag. |
token |
An OAuth token created with |
n |
Maximum number of media to return. |
lat |
Latitude of the center search coordinate |
lng |
Longitude of the center search coordinate |
distance |
Default is 1km (distance=1000), max distance is 5km. |
folder |
If different than |
mindate |
Minimum date for search period |
maxdate |
Maximum date for search period |
verbose |
If |
sleep |
Number of seconds between API calls (default is 0). |
It is only possible to apply one filter at a time: either search by hashtag OR search by coordinates.
The mindate
and maxdata
search parameters only work when searching
by location, not when searching by tag.
IMPORTANT: After June 1st, 2016 only applications that have passed permission review by Instagram will be allowed to access this API endpoint. See https://www.instagram.com/developer/review/ for more information.
Pablo Barbera [email protected]
## Not run: ## See examples for instaOAuth to know how token was created. ## Searching and downloading 100 public media that mention #obama load("my_oauth") obama <- searchInstagram( tag="obama", token=my_oauth, n=100, folder="obama") ## Searching and downloading pictures sent from Times Square with a minimum date ## of 2013-12-31 and a maximum date of 2014-01-01 tsq <- searchInstagram( lat=40.7577, lng=-73.9857, distance=500, token=my_oauth, n=500, folder="timessquare", mindate="2014-12-31", maxdate="2014-01-01") ## End(Not run)
## Not run: ## See examples for instaOAuth to know how token was created. ## Searching and downloading 100 public media that mention #obama load("my_oauth") obama <- searchInstagram( tag="obama", token=my_oauth, n=100, folder="obama") ## Searching and downloading pictures sent from Times Square with a minimum date ## of 2013-12-31 and a maximum date of 2014-01-01 tsq <- searchInstagram( lat=40.7577, lng=-73.9857, distance=500, token=my_oauth, n=500, folder="timessquare", mindate="2014-12-31", maxdate="2014-01-01") ## End(Not run)