I am trying to setup REST API client for Exact online Netherlands. I am using Oltu library for OAuth authorization. Here is my code:
OAuthAuthzResponse oar = OAuthAuthzResponse.oauthCodeAuthzResponse(httpReq);
String code = oar.getCode();
System.out.println(code);
OAuthClientRequest oAuthRequest;
oAuthRequest = OAuthClientRequest
.tokenLocation("https://start.exactonline.nl/api/oauth2/token")
.setGrantType(GrantType.AUTHORIZATION_CODE)
.setClientId("CLIEN_ID_HERE")
.setClientSecret("SECRET_HERE")
.setRedirectURI("http://localhost:8080/exact/returnTo")
.setCode(code)
.buildBodyMessage();
OAuthClient client = new OAuthClient(new URLConnectionClient());
OAuthJSONAccessTokenResponse oauthResponse = client.accessToken(oAuthRequest, OAuth.HttpMethod.POST);
LOGGER.info(oauthResponse.getAccessToken());
However, I am getting invalid_request error
org.apache.oltu.oauth2.common.exception.OAuthProblemException: invalid_request
at org.apache.oltu.oauth2.common.exception.OAuthProblemException.error(OAuthProblemException.java:59)
at org.apache.oltu.oauth2.client.validator.OAuthClientValidator.validateErrorResponse(OAuthClientValidator.java:63)
Can someone please me ?
In the end it was very simple. just needed to be patient ;)
So posting answer.
Just follow this blog https://www.jasha.eu/blogposts/2013/09/retrieve-facebook-profile-data-java-apache-oltu.html
Related
async Task AddVideoCommentAsync(string commentToAdd, string videoID, YouTubeService youtubeService)
{
CommentSnippet commentSnippet = new CommentSnippet();
commentSnippet.TextOriginal = commentToAdd;
Comment topLevelComment = new Comment();
topLevelComment.Snippet = commentSnippet;
CommentThreadSnippet commentThreadSnippet = new CommentThreadSnippet();
commentThreadSnippet.ChannelId = "UCsK0terzCGmIPAeGmW-i-VA";
commentThreadSnippet.VideoId = videoID;
commentThreadSnippet.TopLevelComment = topLevelComment;
CommentThread commentThread = new CommentThread();
commentThread.Snippet = commentThreadSnippet;
CommentThreadsResource.InsertRequest insertComment = youtubeService.CommentThreads.Insert(commentThread, "snippet");
await insertComment.ExecuteAsync();
}
This is my Code to Insert a comment on a video of my choice.
What is wrong here? I got this code from another question on here and changed it a bit, but:
Error: Google.Apis.Requests.RequestError
Request had insufficient authentication scopes. [403]
Errors [
Message[Insufficient Permission] Location[ - ] Reason[insufficientPermissions] Domain[global]
]```
According to the official doc of the CommentThreads.insert API endpoint, a prerequisite of calling it is the following:
Authorization
This request requires authorization with at least one of the following scopes (read more about authentication and authorization).
Scope
https://www.googleapis.com/auth/youtube.force-ssl
Therefore, your youtubeService should have been initialized by means of credentials obtained upon an OAuth 2.0 authentication/authorization flow and those credentials should have had attached among their scopes the one specified above.
I am writing a Python program to read line items from Doubleclick Bid Manager using its API, but facing issue while making a query to getlineitems.
To Authenticate, here is my code:
authorize_url = flow.step1_get_authorize_url()
# After entering the verification for code,
code = raw_input('Code: ').strip()
credential = flow.step2_exchange(code)
I successfully get my credential as a oauth2client.client.OAuth2Credentials object.
Then using following parameters, I make a http request.
params = dict(
api_key='xxxxxxxxxxxxxxxxxx' # client secret from the API JSON file
)
url = 'https://developers.google.com/bid-manager/v1/lineitems/downloadlineitems'
r = requests.get(url = url, params=params)
But my request returns 404; not found code. Per the API guidelines (https://developers.google.com/bid-manager/v1/lineitems/downloadlineitems), you need to make following HTTP request.
POST https://www.googleapis.com/doubleclickbidmanager/v1/lineitems/downloadlineitems?key={YOUR_API_KEY}
Any help will be appreciated.
I don't know much about python, but since the call is a POST request, should you be using requests.get()? Is there a request.post() method?
Let me explain my question :
In the image we can see a twitter access_token & secret (present on twitter app details page)
when I use the above two and try to update the status it works.
Twitter twitter = TwitterFactory.getSingleton();
twitter.setOAuthConsumer(Tweet.consumer_key, Tweet.consumer_secret);
twitter.setOAuthAccessToken(new AccessToken(u.getTwittertoken(), u.getTwittersecret()));
twitter.updateStatus("test");
But the oauth_token & oauth_secret that I get through using twitter4j callbackURL
don't work with the above code. I always get Invalid/Expired Token error.
I don't know what can be the error. Because it used to work once, but stopped suddenly (don't know exactly when)
Please help! It'll be great if someone can share their code for both - getting & saving the token into database & then getting it again from the db to update the status.
For those who face the same error, here's what I was doing wrong :
I was trying the token & secret received in twitter-response. Although the correct method is to retrieve them from accessToken which has to be retrieved using oauth_verifier being sent in twitter-response.
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true).setOAuthConsumerKey(Tweet.consumer_key);
cb.setOAuthConsumerSecret(Tweet.consumer_secret);
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
RequestToken requestToken = (RequestToken) mapSession.get("rtoken");
AccessToken accessToken = twitter.getOAuthAccessToken(requestToken, oauth_verifier);
System.out.println("Request Token : " + ToStringBuilder.reflectionToString(requestToken, ToStringStyle.SHORT_PREFIX_STYLE));
System.out.println("Access Token : " + ToStringBuilder.reflectionToString(accessToken, ToStringStyle.SHORT_PREFIX_STYLE));
System.out.println(accessToken.getToken()); //use this further
System.out.println(accessToken.getTokenSecret()); //use this further
anyone ever used C# in combination with the library RestSharp and OAuthBase in order get some interaction with LinkedIn?
I'm looking for a working example using these tools to do proper authorization (oAuth 2.0) and to publish a post using the share API on LinkedIn.
So far I've been successful using these tools to obtain valid access tokens (I can use it to obtain profile information for example), but posting via the share API got me stuck on authentication.
Any help would be very much appreciated!!
it turned out to be much simpler than I was thinking.... (doesn't it allways?)
The main point to take into account is: oAuth 2.0 does not require signatures, nonce, timestamps, authorization headers ... none of that.
If you want to post on LinkedIn using the sahres API and using oAuth2.0 ... OAuthbase is not needed.
Simply follow the oauth 2.0 authentication flow as described here:
http://developer.linkedin.com/documents/authentication
And then you can use the following code as a starting point:
var shareMsg = new
{
comment = "Testing out the LinkedIn Share API with JSON",
content = new
{
title = "Test post to LinkedIn",
submitted_url = "http://www.somewebsite.com",
submitted_image_url = "http://www.somewebsite.com/image.png"
},
visibility = new
{
code = "anyone"
}
};
String requestUrl = "https://api.linkedin.com/v1/people/~/shares?oauth2_access_token=" + accessToken;
RestClient rc = new RestClient();
RestRequest request = new RestRequest(requestUrl, Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("x-li-format", "json");
request.RequestFormat = DataFormat.Json;
request.AddBody(shareMsg);
RestResponse restResponse = (RestResponse)rc.Execute(request);
ResponseStatus responseStatus = restResponse.ResponseStatus;
Happy coding!!
I am trying to use the scribe oAuth plugin (in a grails environment). I am able to get the user to authorize my app and authenticate. I can then get the xml response. my question, though, is how do I re-query a users profile without having to have them re-authorize my app. Once they authorize it the first time, I capture their Token and Secret key. So, shouldn't I be able to re-query the profile (as long as they do not revoke their authorization.)? I was able to do this with the older version of the plugin. The problem is with creating a new token. I don't see a way to create the Authorization token without the Verifier and Request Token (which wont exist because my code is executing the query on their behalf, with their permission.)
If I try to create the token like this:
Token accessToken = new Token()
accessToken.secret="XXX"
accessToken.token = "YYY"
I get an initialization error.
I can't create it like this, because I dont have the Request token and verifier:
Token accessToken = service.getAccessToken(requestToken, verifier);
accessTokenSecret = accessToken.secret
accessTokenKey = accessToken.token
And If i dont have the access token object, I am unable to sign my request. The full code looks like this (assuming their is a request token and verifier)
OAuthService service=new ServiceBuilder()
.provider(LinkedInApi.class)
.apiKey(apiKey)
.apiSecret(apiSecret)
.build();
Verifier v = new Verifier(ver);
Token accessToken = service.getAccessToken(rt, v);
accessTokenSecret = accessToken.secret
accessTokenKey = accessToken.token
OAuthRequest request = new OAuthRequest(Verb.GET, apiUrl);
service.signRequest(accessToken, request);
Response response = request.send();
xmlString=response.getBody();
Thanks for your help
jason
well, after some time, I got this to work:
public getProfileWithTokens(getAccessToken, getAccessTokenSecret){
Token newAccessToken = new Token(getAccessToken, getAccessTokenSecret);
String xmlString =""
OAuthService service=new ServiceBuilder()
.provider(LinkedInApi.class)
.apiKey(apiKey)
.apiSecret(apiSecret)
.build();
OAuthRequest request = new OAuthRequest(Verb.GET, apiUrl);
service.signRequest(newAccessToken, request);
Response response = request.send();
xmlString=response.getBody();
}