Problems to access an API in R - r

I am trying to download some data from an API.
Following the site documentation:
library(jsonlite)
document <- fromJSON("https://api.gurufocus.com/public/user/{your personal token?}/stock/WMT/keyratios");
epv <- document$Valuation$`EPV`
cat(epv)
I inserted my token, but unfortunately, I get this error:
Error in open.connection(con, "rb") : HTTP error 404.
Any idea to solve this problem?
Best regards

Up front: remove the {, ?} from the url.
Replace more of the string. If you notice in their examples:
Request
Method URL
GET https://api.gurufocus.com/public/user/{your personal token?}/stock/{symbol?}/financials
Example https://api.gurufocus.com/public/user/{your personal token?}/stock/WMT/financials
The {symbol?} is replaced with WMT. I'm inferring you need to do with same with your token.
If I call
https://api.gurufocus.com/public/user/{abcd1234?}/stock/WMT/financials
(where abcd1234 is a known fake token), I get a 404 Not Found. I believe this is because the question mark breaks the URL into a path component
https://api.gurufocus.com/public/user/{abcd1234
and arguments
}/stock/WMT/financials
However, when I do:
https://api.gurufocus.com/public/user/abcd1234/stock/WMT/financials
I get a 401 Unauthorized, meaning that it parsed a token out of it, found the endpoint, and the token is not sufficient (which I know) to authorize access.

Related

HERE.com Places API, "ApiKey is missing" error message, but it isn't

I've tried the below request (with two different proper API keys), on the HERE Places API, but I get an auth error.
Request:
https://places.sit.ls.hereapi.com/places/v1/autosuggest
?at=40.74917,-73.98529
&q=chrysler
&apiKey=g51V9*****N4-_GTA
Response:
401
{
"error": "Unauthorized",
"error_description": "ApiKey is missing."
}
I've also tried OAuth, I can get the request token, but when I use this for the places request I get an HTML webpage (for HERE place API) as the response, rather than an expected JSON or XML reponse.
Is anyone able to get any of the example requests to work for Places API?
I had this issue before aswell. Trying the exact same request as you, in Postman with my own apiKey, made the request successfull.
Try making the URL a single line, there might be newline characters hidden somewhere.
This has solved this issue for me many times using this API.
Example:
https://places.sit.ls.hereapi.com/places/v1/autosuggest?at=40.74917,-73.98529&q=chrysler&apiKey=g51V9*****N4-_GTA
You need to check the key name it may wrong
you should check it out into the documentation of api. and see key name
try key name apikey or api_key or api-key instead of apiKey
https://places.sit.ls.hereapi.com/places/v1/autosuggest
?at=40.74917,-73.98529
&q=chrysler
&apikey=g51V9*****N4-_GTA
Please refer to this guide for the updated list of domains to use with apiKey.
For places, the domain is: places.ls.hereapi.com
Disclosure: I'm a product manager at HERE Technologies
In my case I was using : https://github.com/julianshen/gin-limiter with the provided example

WSO2 ESB - HTTP 401 Unauthorized Error

I have been creating a Proxy service using service chaining mechanism.
1. First I make a call to an endpoint, get the result and send the result to a sequence.
2. In the sequence, I have a data mapper and then a property to specify the username and password to a secure endpoint and then send mediator to call an endpoint.
However, I have been getting the following error:
HTTPSender Unable to sendViaPost to url[endpoint Url] org.apache.axis2.AxisFault: Transport error: 401 Error: Unauthorized,
With the description as "This request requires HTTP authentication"
The solution I have tried:
1. Tried adding a property "FORCE_HTTP_1.0" to true before making a call to the endpoint.
But nothing seems to work. Any help would be appreciated.
Thanks in advance.
If your backend requires Basic authentication, set the following property before your backend call.
Mmh seems like it's not possible to paste Code from my iPhone. Hope the link works.
https://docs.wso2.com/display/ESB470/Enabling+HTTP+Basic+Authentication+through+a+Proxy+Server
Just set the property "Proxy-Authorization"

Amending scope values in token request causes problems accessing APIs afterwards

I am encountering the following error after amending a scope value being sent in the headers of a token POST request against the token API endpoint for our WSO2 instance:
ERRORS.900901
Invalid CredentialsAccess failure for API: /scheme/v1, version: v1 with key: fa41109938522762bcca953336f0e0e2.
Make sure your have given the correct access token
This error comes after I successfully get a token returned and then use that token for a an API setup in WSO2 publisher. This particular endpoint in the error does not actually have any scopes applied to it which causes me some confusion about why this error comes up since its not a scope protected endpoint so my token shouldn't matter?
This happened after I realised there was a typo in a scope value I was sending in the POST request and so I updated it accordingly.
If I leave the typo in I can use the token generated for a subsequent API request and dont get this error.
Am I right in thinking that tokens are generated based on the list of scopes returned back by the Token API for the given user?
I have tried manually revoking the access token using a cURL command as documented here and generating a new one using the corrected scope names, but still this error comes back after trying to access that API.
What could be the issue here?
Thanks
This error comes after I successfully get a token returned and then
use that token for a an API setup in WSO2 publisher. This particular
endpoint in the error does not actually have any scopes applied to it
which causes me some confusion about why this error comes up since its
not a scope protected endpoint so my token shouldn't matter?
This also can happen if there were any errors while validating the token. This doesn't look like a scope issue. So if you can provide the corresponding logs in wso2carbon.log, I can tell the exact reason.
Am I right in thinking that tokens are generated based on the list of
scopes returned back by the Token API for the given user?
Yes.

Linkedin API access token generation error

i am trying to generate access token to collect linkedin data. I followed the instructions provided in the linkedin API documentaion. I created an app in developers page and got the following:
Application Details
• Company:
Fresher
• Application Name:
xxxxxxxxxx
• API Key:
75pcum6zb2cael
• Secret Key:
xxxxxxxxxxxxxxxx
• OAuth User Token:
xxxx-xxxx-xxxx-xxxx-xxxxxxxxxx
• OAuth User Secret:
xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx
Using the API Key i generated the authorization_code with the URL:
https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=75pcum6zb2cael&state=DCEEFWF45453sdffef424&redirect_uri=https://www.google.com
but when i finally tried to generate the access token using the below URL, i got an error response :
https://www.linkedin.com/uas/oauth2/accessToken?grant_type=authorization_code&code=AUTHORIZATION_CODE&redirect_uri=https://www.google.com&client_id=75pcum6zb2cael&client_secret=xxxxxxxxxxxxxxxx
{"error_description":"missing required parameters, includes an invalid
parameter value, parameter more than once. : Unable to retrieve access
token : appId or redirect uri does not match authorization code or
authorization code expired","error":"invalid_request"}
Even after multilple validations, the same error messages appears.
please help. thanks.
finally, i got the access token. The authorization code expires in 20 seconds, so the access token URL must be called immediately after generating the authorization code.
Well, I went through the same problem and here is the process which i went through to fix it.
STEP#1: Authentication:
Firstly, the authentication API is to be hit to fetch the authentication token.
For this, a URL with Encoded parameters is to be hit as a GET request.
Example: https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id=[your_client_id]&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Flinkedin%2Fcallback&scope=r_emailaddress
Please note that here, the parameters are to be encoded programatically.
My non-encoded callback URL is: http://localhost:8080/linkedin/callback
Therefore, my encoded URL is: http%3A%2F%2Flocalhost%3A8080%2Flinkedin%2Fcallback
Once you hit this as a GET request, you will receive a callback with a code and an optional state parameter.
STEP#2: Getting Access Token:
There are three pre-requisites to this call:
The call must be POST
It must have a header Content-Type with value application/x-www-form-urlencoded
The data must be sent in request body.
The value of redirect_url MUST BE SAME as in the previous call.
In my case, it was: http://localhost:8080/linkedin/callback
Now the trick here is, that the call in (STEP#1 Authentication) was a GET request. Therefore, the redirect_url had to be programatically encoded.
Since the second call for is POST and is also application/x-www-form-urlencoded encoded, therefore the request body parameters do not have to be explicitly encoded. So, in this case, the redirect_uri would be sent as-is (http://localhost:8080/linkedin/callback)
Here is a snapshot of my Access Token API via postman:
My problem was in redirect_uri which contained url with query parameters (like redirect_uri=encodeURIComponent(http://example.com/callback?query=string)).
If redirect url is completely different linkedin will show you an error before showing you login form, but if redirect_url matches what you specified in linkedin app and contains extra query parameters, you'll not get an error, so once login form is submitted you'll get an invalid code and as a result error as above.
This error may be scopes related.
On the details of your application when selecting scopes there is this message:
Selecting both r_basicprofile and r_fullprofile is redundant.
r_basicprofile will be selected if neither r_basicprofile nor
r_fullprofile is checked.
If you are selecting both r_basicprofile and r_fullprofile just uncheck r_basicprofile or remove it from your Authorization Code Request.
I had the same problem, in my case I was using different redirect_uri for authorization and for access token. I had "proxy": "localhost:3001" in my package.json, and it overriden my request_uri.
So my suggestion: make sure the hosts and redirect_uri are all the same for two requests (both backend and server side).

400 bad request when requesting Facebook access token

I'm getting a 400 bad request error from Facebook when requesting an access token. My return_uri includes a query string parameter which is causing the problem. I've encoded the return_uri but I stil get the error. Can anyone help me with this?
Here is the request I'm sending to Facebook:
"https://graph.facebook.com/oauth/access_token?client_id=IDb&client_secret=SECRET&redirect_uri=http%3a%2f%2fexample.com%2fOAuthHttpHandler.ashx%3fReturnUrl%3d%2fpage.aspx&code=CODE"
I'm getting an "Error validating verification code." error message.
I've done a little more digging and found that the redirect_uri below works fine:
"http://example.com/OAuthHttpHandler.ashx?ReturnUrl=page.aspx"
But if I pass across a return url of "/secure/page.aspx" validation fails. I've tried encoding the forward slashes but no luck.
Unfortunately, the Facebook Oauth implementation doesn't handle url parameters in the return_uri querystring well, even when they are correctly encoded. There are several threads in the fb developer forums discussing this issue:
http://forum.developers.facebook.net/viewtopic.php?pid=237845
http://forum.developers.facebook.net/viewtopic.php?pid=239866
http://forum.developers.facebook.net/viewtopic.php?pid=255231
Until its fixed on their end, you'll have to use an alternative method of passing state: session, cookie, or building a simple page-specific identifier into the url.
After hours of searching around I finally found a good solution to the facebook access_token request returning "Bad Request 400".
The return_uri param sent to "https://graph.facebook.com/oauth/access_token" must be exactly the same uri as the one sent "to https://graph.facebook.com/oauth/authorize"
What I did was just replace the slashes with dashes when I send 'em to facebook. Then on the callback, replace the dashes with slashes again!

Resources