This package is wrapping Bit.ly API, Goo.gl and Ow.ly support. In order to begin downloading usefull statistics and shortening URLs, there is one requirement, which is to gain your API Key (no OAuth support at this stage, see later with a new package called ‘urlshorteneR’) - so-called “Generic Access Token”.
For that there are two ways.
The first one is to go to https://bitly.com/a/oauth_apps and generate one yourself. Then, you will need to execute rbitlyApi("Your Generic Access Token")
method. This is a requirenment to work with all bit.ly
functions in this package.
Or you can retrieve your “Generic Access Token” using your username and password to the account which automatically sets your API Key. Meaning you can execute rbitlyApi_up("YourUsername", "YourPassword")
, which not only will print your API Key (just in the case you will need it) but also, using the method above, “store” it R.
For bit.ly
either one is OK, for Ow.ly you will need to have your API key already and for goo.gl
, follow ?rbitlyApi
(“auth_googl” method).
Official API documentation http://dev.bitly.com/user_metrics.html.
Method below returns my most-clicked Bit.ly links (ordered by number of clicks) in a given time period.
library(RBitly)
## Old
## rbitlyApi("0906523ec6a8c78b33f9310e84e7a5c81e500909") # Now officially deprecated
## Now
options(Bit.ly = "0906523ec6a8c78b33f9310e84e7a5c81e500909", Ow.ly = "F1QH-Q64B-BSBI-JASJ", Goo.gl = "AIzaSyAbJt9APfph1JGIhflkoH9UuGhOACntOjw")
user_Metrics_PopularLinks(unit = "month", units = -1, limit = 100)
## link clicks
## 1 http://bit.ly/DPetrov 5
## 2 http://bit.ly/1IZgFLV 1
## 3 http://bit.ly/1hpfNzy 1
Official API documentation http://dev.bitly.com/link_metrics.html.
This returns users who have encoded http://bit.ly/DPetrov
link sorted by the number of clicks on each encoding user’s link.
link_Metrics_EncodersByCount(link = "http://bit.ly/DPetrov", my_network = "false", limit = 100)
## count link user ts
## 1 6 http://bit.ly/1hpfNzy o_5udd1hb1d8 2014-02-24 14:19:45
Official API documentation http://dev.bitly.com/user_info.html.
The first method returns an information about myself, whereas the second one returns a list of tracking domains I have configured (I have none).
user_Info()
## ReturnValues ReturnValuesDescription
## 1 R_376c40c13a174e8e90e2f550e6b9e935 apiKey
## 2 bit.ly domain_options1
## 3 bitly.com domain_options2
## 4 j.mp domain_options3
## 5 2014-02-24 14:19:16 member_since
## 6 0 has_master
## 7 http://bitly.com/u/o_5udd1hb1d8.png profile_image
## 8 49683260 share_accounts.numeric_id
## 9 Leaker_PRG share_accounts.account_login
## 10 twitter share_accounts.account_type
## 11 eeb9c31349cfc46e914f47925531b9e6e715d4fc share_accounts.account_id
## 12 TRUE share_accounts.primary
## 13 FALSE share_accounts.visible
## 14 FALSE share_accounts.is_delegated
## 15 1393251556 share_accounts.connected
## 16 Leaking Stuff in PRG share_accounts.full_name
## 17 Leaker_PRG share_accounts.account_name
## 18 TRUE has_password
## 19 Leaking Stuff in PRG full_name
## 20 FALSE is_enterprise
## 21 private default_link_privacy
## 22 @Leaker_PRG display_name
## 23 o_5udd1hb1d8 login
## 24 TRUE is_verified
## 25 http://bitly.com/u/o_5udd1hb1d8 profile_url
user_TrackingDomains()
## It seems that you don't have any tracking domains.
Official API documentation http://dev.bitly.com/domains.html.
This will query whether a given domain is a valid Bit.ly PRO domain (nyti.ms is).
bitly_pro_domain(domain = "nyti.ms")
## A short domain: nyti.ms is a valid bitly pro domain
# check later & helm me with your Ow.ly API key. Please do contribute back.
# links_ShortenOwly("")
# link_Metrics_Owly("")
g2 <- links_ShortenGoogl(longUrl = "https://developers.google.com/url-shortener/v1/url/insert")
g2
## kind id
## 1 urlshortener#url https://goo.gl/YhtZe
## longUrl
## 1 https://developers.google.com/url-shortener/v1/url/insert
g1 <- links_ExpandGoogl(shortUrl = "http://goo.gl/vM0w4", showRequestURL = F)
g1
## $original_data
## kind id
## 1 urlshortener#url http://goo.gl/vM0w4
## longUrl
## 1 http://www.bi-verdict.com/fileadmin/FreeAnalyses/consolidations.htm
## status
## 1 OK
##
## $analytics
## NULL
Based on http://dev.bitly.com/
http://dev.bitly.com/user_info.html | Implemented Yes/No |
---|---|
/v3/oauth/app | (NOT, see below) |
/v3/user/info | Yes |
/v3/user/link_history | Yes |
/v3/user/network_history | NOT |
/v3/user/tracking_domain_list | Yes |
http://dev.bitly.com/link_metrics.html | Implemented Yes/No |
---|---|
/v3/link/clicks | Yes |
/v3/link/countries | Yes |
/v3/link/encoders | Yes |
/v3/link/encoders_by_count | Yes |
/v3/link/encoders_count | Yes |
/v3/link/referrers | Yes |
/v3/link/referrers_by_domain | Yes |
/v3/link/referring_domains | Yes |
http://dev.bitly.com/user_metrics.html | Implemented Yes/No | Premium |
---|---|---|
/v3/user/clicks | Yes | |
/v3/user/countries | Yes | |
/v3/user/popular_earned_by_clicks | NOT | Yes |
/v3/user/popular_earned_by_shortens | NOT | Yes |
/v3/user/popular_links | Yes | |
/v3/user/popular_owned_by_clicks | NOT | Yes |
/v3/user/popular_owned_by_shortens | NOT | Yes |
/v3/user/referrers | Yes | |
/v3/user/referring_domains | Yes | |
/v3/user/shorten_counts | Yes |
http://dev.bitly.com/domains.html | Implemented Yes/No | Premium |
---|---|---|
/v3/bitly_pro_domain | Yes | No |
/v3/user/tracking_domain_clicks | NOT | Yes (cannot do unless sombody helps) |
/v3/user/tracking_domain_shorten_counts | NOT | Yes (cannot do unless sombody helps) |
http://dev.bitly.com/links.html | Implemented Yes/No | Premium |
---|---|---|
/v3/expand | Yes | |
/v3/info | Yes | |
/v3/link/lookup | Yes | |
/v3/shorten | Yes | |
/v3/user/link_edit | NOT | No |
/v3/user/link_lookup | NOT | No |
/v3/user/link_save | NOT | No |
/v3/user/save_custom_domain_keyword | NOT | Yes |
At the moment no OAuth support is present so that one must use HTTP Basic Authentication Flow, which requires Generic Access Token
from https://bitly.com/a/oauth_apps (see above).
Lastly, sometimes, only a small subset of input paramaters has been implemented. Again contact me and I will consider a change.