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
Related
I am trying to test out the Dun and Bradstreet API in R using httr.
I am trying to leverage the oauth2 functionality in httr.
Here is my code:
library(httr)
library(jsonlite)
clientid = redacted
secret = redacted
app <- oauth_app(appname = "Dun", key = clientid, secret = secret)
endpoint <- oauth_endpoint(base_url = "https://login.bisnode.com/sandbox/v1/token.oauth2", authorize="https://login.bisnode.com/sandbox/v1/token.oauth2", access = "https://login.bisnode.com/sandbox/v1/token.oauth2")
token <- oauth2.0_token(endpoint = endpoint, app = app, scope = "credit_data_companies", user_params = list(grant_type = "client_credentials"))
In Rstudio I get this message:
Waiting for authentication in browser... Press Esc/Ctrl + C to abort
In the browser, I get this message:
{"error":"invalid_request","error_description":"grant_type is
missing"}
I am sure this is something simple, but I could not find a solution in any other posts. Thank you!
I use Oauth2 authorization to get the token for REST API. I tested the setting in SoapUI and it is working with the Resource Owner Password Credential Grant as shown below.
The setting in the SoapUI testing is working
Now, I want to retrieve the token through R httr library, but I don’t know how to set the resource owner name and password in the R code. Here is my Code
library(httr)
library(jsonlite)
r <- POST("https://XXXXXXX.com/authservice/connect/token",
config = list(),
body = list(
# grant_type = "RESOURCE_OWNER_PASSWORD_CREDENTIALS",
grant_type = "resource_owner_credentials",
resourceOwnerName = "ResourceName",
resourceOwnerPassword = "Resourcepwd",
# resource_Owner_Name = "ResourceName",
# resource_Owner_Password = "Resourcepwd",
# resourceOwner_Name = "ResourceName",
# resourceOwner_Password = "Resourcepwd",
# resource_OwnerName = "ResourceName",
# resource_OwnerPassword = "Resourcepwd",
# resource_Name = "ResourceName",
# resource_Password = "Resourcepwd",
# resource_id = "ResourceName",
# resource_secret = "Resourcepwd",
client_id = "ClientIDname",
client_secret = "Clientpassword",
scope = "xxxGroup"
),
encode = "form"
)
warn_for_status(r)
content(r)
status_code(r)
I got a 400 error ("unsupported_grant_type" and bad request). I am guessing there may be something wrong with the syntax on the resource onwer name and password, so I also tried all the possible combinations that I commented in above code but they all failed.
My question is: are the parameter names for both resource owner name and password pre-defined by the API document, or they are the fixed names defined by R-httr librabry, regardless what token authorization service?
Can someone help to take a look at? Any input is greatly appreciate!
I have been banging my head over this the whole day. I am trying to access StockTwits API (https://api.stocktwits.com/developers) from an R session. I have earlier accessed the twitter API (via rtweet) without hassles.
I have created an app and got the client id and key (the below are just examples).
app_name = "some.name";
consumer_key = "my_client_id";
consumer_secret = "my_client_key";
uri = "http://iimb.ac.in" # this is my institute's homepage. It doesn't allow locahost OR 127.0.0.1
scope = "read,watch_lists,publish_messages,publish_watch_lists,direct_messages,follow_users,follow_stocks";
base_url = "https://api.stocktwits.com/api/2/oauth"; # see https://api.stocktwits.com/developers/docs/api
The procedure is to create an oauth2.0 app and endpoint. Then call oauth2.0_token.
oa = httr::oauth_app(app_name, key = consumer_key, secret = consumer_secret, redirect_uri = uri);
oe = httr::oauth_endpoint("stocktwits", "authorize", "token", base_url = base_url);
mytoken = httr::oauth2.0_token(oe, oa, user_params = list(resource = base_url), use_oob = F); # use_oob = T doesn't work.
After firing the above, it takes me to the browser for sign-in. I sign-in and it asks me to connect. After that, I am taken back to my URI plus a code, i.e. https://www.iimb.ac.in/?code=295ea3114c3d8680a0ed295d52313d7092dd90ae&state=j9jXzEqri1
Is the code my access token or something else? The oauth2.0_token() call keeps waiting for the code since the callback is not localhost. I didn't seem to get a hang of that.
I then try to access the API using the above code as access token but I am thrown "invalid access token" error. The format is described in https://api.stocktwits.com/developers/docs/api#search-index-docs
Can someone tell me what I have missed? If required I can share my app_name, consumer_key and consumer_secret for replication.
NOOB question related to R blastula.
I am trying to send an email with blastula using office365.
I was able to create a credentials file but can't seem to send a simple test email:
require(blastula) ; require(curl)
email <- compose_email(body = "Insert your e-mail body here", footer = "Insert your e-mail footer here")
email %>% smtp_send(from = "me#email.com", to = "someone_else#email.com", credentials = creds_file("C:/Users/me/CREDS_FILE")
)
There seems be a dependency on curl that's throwing the error:
Error in curl::curl_fetch_memory(url, handle = h) : MAIL failed: 530
What am I doing wrong ?
Try use_ssl = TRUE in create_smtp_creds_key. This worked for me.
email <- compose_email(
body = md(
"Your email message"
))
smtp <- create_smtp_creds_key(
id = "outlook",
user = "youremail#outlook.com",
provider = "office365",
host = "smtp.office365.com",
use_ssl = TRUE)
email %>%
smtp_send(to = to,
from = from,
subject = subject,
credentials = creds_key(id = "outlook"))
After doing some searching around I found this question and answer which seemed related. Hadley's suggestion of restarting R and reinstalling {curl} fixed the issue that I was having.
I actually reinstalled both {curl} and {blastula} with
install.packages(c('blastula', 'curl'))
I need to authenticate AWS API in R. I tried using aws.signature package to do the same and I am getting 403 response with error Missing Authentication Token . It seems that I am missing some necessary parameters. Looking for assistance to debug the below code or ways to authenticate AWS API in R.
# To create aws signature for authentication for the rest API call
library(aws.signature)
library(httr)
# validate arguments and setup request URL
current <- Sys.time()
d_timestamp <- format(current, "%Y%m%dT%H%M%SZ", tz = "UTC")
hdrs <- list(`Content-Type` = "application/x-www-form-urlencoded",
Host = "jteti5wnje.execute-api.eu-central-1.amazonaws.com",
`x-amz-date` = d_timestamp)
params <- signature_v4_auth(
datetime = d_timestamp,
region = "eu-central-1",
service = "execute-api",
verb = "GET",
action = "iMetaAPI",
query_args = list(),
canonical_headers = hdrs,
request_body = "json",
key = "***************",
secret = "*****************",
session_token = NULL,
query = FALSE,
algorithm = "AWS4-HMAC-SHA256",
verbose = TRUE)
a <- GET("https://jteti5wnje.execute-api.eu-central-1.amazonaws.com/iMetaAPI",
query = params)
rawToChar(a$content)
A few things:
request_body needs to be the actual body. You're doing a GET() so it should just be NULL or "".
The response from signature_v4_auth() is a list but you don't need all of its elements - probably just the hds$Authorization <- params$SignatureHeader element.
The actual errors you're getting is because you haven't passed the headers. You need to pass the headers to GET() with something like: do.call(add_headers, hdrs) so you can do:
a <- GET("https://jteti5wnje.execute-api.eu-central-1.amazonaws.com/iMetaAPI", do.call(add_headers, headers))
That will probably work, or you'll at least get a more informative error.