It appears that Yahoo has discontinued support for oauth1.0. I am trying to update my R code to use oauth2.0 using the httr package, and am stumped. I am able to get token, but am unable to use the token to query the api.
I continue to get "You are not authorized to view this league".
options("httr_oob_default" = T)
library(httr)
b_url <- "https://fantasysports.yahooapis.com" #base url
#Create Endpoint
yahoo <- httr::oauth_endpoint(authorize = "https://api.login.yahoo.com/oauth2/request_auth"
, access = "https://api.login.yahoo.com/oauth2/get_token"
, base_url = b_url)
#Create App
yahoo_app <- httr::oauth_app("yahoo", key=cKey, secret = cSecret,redirect_uri = "oob")
#Open Browser to Authorization Code
httr::BROWSE(httr::oauth2.0_authorize_url(yahoo, yahoo_app, scope="fspt-r"
, redirect_uri = yahoo_app$redirect_uri))
#Code = zp6v82a
#Create Token
yahoo_token<- httr::oauth2.0_access_token(yahoo,yahoo_app,code="zp6v82a")
Now im not sure where to go from here.
If there is any advice, or an easier method please let me know. I am an amateur coder so please, be gentle.
Related
I am trying to retrieve tweets from twitter on a full archive basis. However, I finally managed to work things out on my developer page, but the code seems to stumble upon an error that I can not find anywhere on the internet. This is my code without my tokens:
install.packages("RCurl")
library("RCurl")
install.packages("rtweet")
library("rtweet")
consumer_key <- ".."
consumer_secret <- ".."
access_token <- ".."
access_secret <- ".."
app <- "..."
token = rtweet::create_token(app,consumer_key,consumer_secret,access_token,access_secret)
dataBTC1 <- search_fullarchive("Bitcoin", n = 1000, env_name = "Tweets", fromDate = "201501010000")
And this is the error I get:
Error in tweet(x$quoted_status) :
Unidentified value: edit_history, edit_controls, editable.
Please open an issue and notify the maintainer. Thanks!
Literally no idea what it means and how to solve it if possible. Can anyone help me?
Thanks!
These errors occur because the R package you are using (rtweet) does not "know" about the three new fields that were added to the Tweet object when the new editable Tweets feature was released. You will need to ask the rtweet maintainers (as it mentions in the error message) to enable support for these fields in their library, or find an alternative way to call the API.
I am getting 500 status. Can you anyone help me on this please
I am trying to connect Salesforce using R when i try perform the login operation. I am not successful, can you please look into this code and correct me where i am missing.
library(RCurl)
library(httr)
body1 = '<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<login xmlns="urn:partner.soap.sforce.com">
<username>xxxxxx.Test#xxxxxx.com.xxxxxxx</username>
<password>xxxxxxxxxxxx</password>
</login>
</s:Body>
</s:Envelope>'
x <- httr::POST(url = "https://test.salesforce.com/services/Soap/48.0", body = body1, content_type("text/xml;charset=UTF-8"),SOAPAction = "login")
x$status_code
Thanks for answering the questions. After several tries, I understood there was some issue in the headers. I fixed the headers and its now working great. I am able to perform a query in Salesforce without any issues. I have posted my complete code here so anyone can make use for it. I am not an expert in this but still managed with this code.
#######Required Packages
library(RCurl)
library(httr)
library(XML)
library(jsonlite)
library(xml2)
library(magrittr)
library(randomNames)
library(rlang)
library(generator)
library(stringr)
require(data.table)
body1 = '<?xml version="1.0" encoding="utf-8"?>\
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">\
<s:Body>\
<login xmlns="urn:partner.soap.sforce.com">\
<username>XXXXXXXXXXXXXX</username>\
<password>XXXXXXXXXXXXXXX</password>\
</login>\
</s:Body>\
</s:Envelope>\n'
require(httr)
################################Posting the Login##############################################
result <- POST("https://test.salesforce.com/services/Soap/u/48.0",body = body1,add_headers(.headers = c("Content-Type"="text/xml",'SOAPAction' = "https://test.salesforce.com")))
##############Parsing XML###############################################################
Output <- content(result)
doc = xmlTreeParse(Output, useInternal = TRUE)
top = xmlRoot(doc)
xmlName(top)
names(top)
names(top[[1]] [[1]] [[1]])
Session = top[[ 1 ]] [[1]] [[1]] [["sessionId"]]
SessionId <- Session [1][1]$text
tok <- xmlToList(SessionId)
Se <- paste("Bearer",tok,Sep="")
Se = trimws(Se)
Sever = top[[ 1 ]] [[1]] [[1]] [["serverUrl"]]
SessionURL <- Sever [1][1]$text
################SF Query###########################################
SFQuery <- "SELECT Id,FirstName FROM Conatct limit 10"
SFQuery_Req <- GET(Pam,query = list(q=SFQuery),add_headers(Authorization=Se))
SFQuery_Con <- content(SFQuery_Req, as = 'text') %>% fromJSON()
SFQuery_Con_DF <- data.frame(SFQuery_Con$records)
It can be many things, not all related to your code...
Your SOAP namespaces might be wrong. Maybe try with SoapUI / Postman / curl first and once you get these to work - check the code. Try with this version of the tags
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:partner.soap.sforce.com">
<soapenv:Body>
<urn:login>
<urn:username>usernamegoeshere</urn:username>
<urn:password>passwordgoeshere</urn:password>
</urn:login>
</soapenv:Body>
</soapenv:Envelope>
Log in to the SF org manually and check that user's login history at bottom of the page. Do you see your attempt at all? If not - are you sure you're connecting to right place (production vs sandbox)? Or maybe you have some proxy installed by your corporate IT and it just swallows the connections... If there's an entry in the login history - does it say invalid password? Too many failed login attempts? Security token needed?
It's possible admin disabled logging in from generic test.salesforce.com and you'll have to use what you see in Setup -> My Domain.
It's possible admin set your user for Single Sign-On (do you see normal SF login page or are redirected to some Active Directory stuff for example). If that's the case it'll be trickier to connect via API.
Maybe your user is not API-enabled, that'd be a Profile / Permission Set thing. Do you use system administrator account? Are there any login policies on the profile like access only from certain IPs or during certain login hours.
I maintain an R package called {salesforcer} that allows users to interact with 6 different Salesforce APIs (SOAP, REST, Bulk 1.0, Bulk 2.0, Metadata, Reports and Dashboards) to manage their Orgs. If one of these APIs suite your needs I would recommend using the package so that you do not need to write the code from scratch. Below is an example for how to connect using either OAuth 2.0, sometimes referred to as Single Sign-On, or with a username, password, and security token. Please visit the package's documentation site for additional detail and vignettes at: https://stevenmmortimer.github.io/salesforcer/
# install.packages('salesforcer')
library(salesforcer)
# Using OAuth 2.0 authentication
sf_auth()
# Using Basic Username-Password authentication
sf_auth(username = "test#gmail.com",
password = "{PASSWORD_HERE}",
security_token = "{SECURITY_TOKEN_HERE}")
# pull down information of person logged in
# it's a simple API call to get started
# and confirm connection to the APIs
user_info <- sf_user_info()
sprintf("Organization Id: %s", user_info$organizationId)
#> [1] "Organization Id: 00D6A0000003dN3UAI"
sprintf("User Id: %s", user_info$userId)
#> [1] "User Id: 0056A000000MPRjQAO"
I just received a public and private key to connect to ICObench api. I'm quite used to use R, but I admit i found no accurate info on how to authenticate to an API that asks for a public an private key.
Here is their api page telling how to authenticate (though not with R).
I tried the following code (using httr package), which i found on this stackoverflow post :
req <- GET("https://icobench.com/api/v1/icos/ratings",
authenticate("user#gmail.com" , "password"),
add_headers(privateKey = privatekey ),
add_headers(publicKey = publickey))
stop_for_status(req)
content(req
)
But this code does not seem to work with 2 keys/2 headers. I get the following error message :
"Not provided or missing X-ICObench-Key"
Any idea how to authenticate properly to this API ? There's some nice tutorials for the rest :)
Thanks for your help
You can give the following a try
signature <- openssl::base64_encode(openssl::sha384("", privateKey))
req <- GET("https://icobench.com/api/v1/icos/ratings",
authenticate("user#gmail.com" , "password"),
add_headers("X-ICObench-Sig"=signature),
add_headers("X-ICObench-Key"=publickey))
stop_for_status(req)
content(req)
Using rvest package, I am trying to scrape data from my LinkedIn profile.
These attempts:
library(rvest)
url = "https://www.linkedin.com/profile/view?id=AAIAAAFqgUsBB2262LNIUKpTcr0cF_ekoX9ZJh0&trk=nav_responsive_tab_profile"
li = read_html(url)
html_nodes(li, "#experience-316254584-view span.field-text")
html_nodes(li, xpath='//*[#id="experience-610617015-view"]/p/span/text()')
don't find any nodes:
#> {xml_nodeset (0)}
Q: How to return just the text?
#> "Quantitative hedge fund manager selection for $650m portfolio of alternative investments"
EDIT:
LinkedIn has an API, however for some reason, below returns only the first two positions of experience, no other items (like education, projects). Hence the scraping approach.
library("Rlinkedin")
auth = inOAuth(application_name, consumer_key, consumer_secret)
getProfile(auth, connections = FALSE, id = NULL) # returns very limited data
You are making things unnecessarily difficult... All you need to do is issue a GET request to https://api.linkedin.com/v1/people/~?format=json after obtaining an OAuth 2.0 token from Linkedin. In R, you can do this using jsonlite:
library(jsonlite)
linkedin <- fromJSON('https://api.linkedin.com/v1/people/~?format=json')
position <- linkedin$headline
You must have the 'r_basicprofile' member permission on your oauth token.
I am using RFacebook package to do data mining.
For example, to get the facebook page then we do
fb_page <- getPage(page="facebook", token=fb_oauth)
In my case is it is a private group and the URL is something like this. So how do I get the page info for a group? I tried the following but got the following error.
Error in callAPI(url = url, token = token) : Unknown path
components: /posts
my_page <- getPage(page="group/222568978569", token=my_oauth)
This isn´t a reproducible example because the page you mention doesn´t exist. But I suggest that you check that this group has authorized your app. Note that after the introduction of version 2.0 of the Graph API, only friends/groups who are using the application that you used to generate the token to query the API will be returned.