getURL with user, pwd and AppID - r

I'm trying to make the following request :
library("RCurl")
getURL("https://api.example.com/resource",
userpwd ="username:password",param="ApplicationID")
But I have this error :
The required parameter 'Username' was not found.
Any ideas?

Try this:
opts = curlOptions(userpwd = "user:swd", param= "AppID")
getURL("url",.opts=opts)

Related

Issue accessing RapidAPI with httr / R - Status: 401

I am trying to access a RapidAPI with the httr package in R as follows:
library(httr)
url <- "https://extract-news.p.rapidapi.com/v0/article"
queryString <- list(url = "https://www.theverge.com/2020/4/17/21224728/bill-gates-coronavirus-lies-5g-covid-19")
response <- VERB("GET", url, addheaders(x_rapidapi_key ="my-api-key", x_rapidapi_host = "extract-news.p.rapidapi.com"), query = queryString, contenttype("application/octet-stream"))
content(response, "text")
I tried accessing other APIs too. However, I keep getting this error message:
Status: 401
Could you please help me solve this issue?
Thanks a lot in advance!
Try using content_type() and add_headers instead of contenttype and addheaders to tell the server what sort of data you are sending. Read more about the VERB method here.
library(httr)
url <- "https://extract-news.p.rapidapi.com/v0/article"
queryString <- list(url = "https://www.theverge.com/2020/4/17/21224728/bill-gates-coronavirus-lies-5g-covid-19")
response <- VERB("GET", url, add_headers(x_rapidapi-host = 'extract-news.p.rapidapi.com', x_rapidapi-key = '*************************', '), query = queryString, content_type("application/octet-stream"))
content(response, "text")

error in evaluating the argument 'drv' in selecting a method for function 'dbConnect': could not find function "MySQL"

I am getting an error message " error in evaluating the argument 'drv' in selecting a method for function 'dbConnect': could not find function "MySQL""
Here is the part of the code:
library(DBI)
conn <- dbConnect( drv = RMySQL::MySQL(), dbname = "xxx", host = "xxx", username = "xxx", password = "new_password")
dbGetQuery(conn, "SELECT * FROM tech LIMIT 1;")
dbDisconnect(conn)
If you're using a script in an interactive session, call library(RMySQL) to load the package.
If you get this error while developing a package, add RMySQL to the Imports field of your DESCRIPTION file. You can do that with usethis::use_package("RMySQL").

Gmail authentication error: invalid_request Missing required parameter: client_id

I am facing an issue while trying to access gmail through gmailr package.
Had given then input for Client and secret_key and it is able to run gmail_auth(..........). However, when I am trying to extract messages() I am getting 400 error.
Tried using .json secret_file as well. But same result!
Can you explain where I am missing the client_id?
gmail_auth(scope = c("read_only", "modify", "compose", "full"), id = the$id,secret = the$secret, secret_file = NULL)
messages(search="XX",num_results = 2, label_ids = NULL,include_spam_trash = FALSE,page_token = NULL, user_id = "me")
That’s an error.
Error: invalid_request
Missing required parameter: client_id
Learn more
Request Details
scope=https://www.googleapis.com/auth/gmail.readonly https://www.googleapis.com/auth/gmail.modify https://www.googleapis.com/auth/gmail.compose https://mail.google.com/
redirect_uri=urn:ietf:wg:oauth:2.0:oob
response_type=code

Importing data to google analytics with R

I would like to automate the data upload to GoogleAnalytics with R, but cannot find the way to do it.
So far I have done this:
Get google auth token based on googleAuthR package:
token <- Authentication$public_fields$token
Generate url to the upload endpoint:
url.template <- "https://www.googleapis.com/upload/analytics/v3/management/accounts/%1$i/webproperties/%2$s/customDataSources/%3$s/uploads"
url <- sprintf(url.template, account.id, web.property.id, data.source)
Call POST using httr package:
httr::content_type("text/csv")
httr::POST(url = url,
body = list(y = httr::upload_file("ga-product-import.csv")),
config = token,
encode = "multipart"
)
So far I am getting 400 response.
I also tried this:
f <- gar_api_generator(url,
"POST",
data_parse_function = function(x) x)
f(the_body = list(y = httr::upload_file("ga-product-import.csv")))
but getting this error:
Error : No method asJSON S3 class: form_file Error in
the_request$status_code : $ operator is invalid for atomic vectors
The library googleAnalyticsR depends on googleAuthR, and has a cost data upload function with help found at ?ga_custom_upload

How to authenticate with reddit using RCurl

I've been trying to authenticate with Reddit from R using RCurl based on this example from Reddit's github:
curl -X POST -d 'grant_type=password&username=reddit_bot&password=snoo' --user 'p-jcoLKBynTLew:gko_LXELoV07ZBNUXrvWZfzE3aI' https://ssl.reddit.com/api/v1/access_token
I've tried to convert it to an RCurl command like so:
postForm("https://ssl.reddit.com/api/v1/access_token?grant_type=password",
username = "MyUserName",
password = "MyPassword",
.opts = list(userpwd = "MyClientid:MySecret")
)
But I get an error: Error: Unauthorized
I'm not sure what I'm doing really with the conversion of the curl command to Rcurl. Thanks for any help you could provide!
Try this httr code:
library(httr)
POST("https://ssl.reddit.com/api/v1/access_token",
body = list(
grant_type = "password",
username = "MyUserName",
password = "MyPassword"
),
encode = "form",
authenticate("p-jcoLKBynTLew", "gko_LXELoV07ZBNUXrvWZfzE3aI")
)

Resources