i am using rest api to get an access toke of my user using following link
https://api.pinterest.com/v1/oauth/token?grant_type=authorization_code&client_id=my id&client_secret=my secret&code="+oauthVerifier+
i am getting the response as
{"status": "failure", "code": 3, "host": "devplatform-devapi-prod-4a8937b3", "generated_at": "Tue, 28 Jun 2016 06:06:56 +0000", "message": "Authorization failed.", "data": null}
what shod i do to get my users access token
Related
I'm getting the following exception when trying to get data from google calendar Please note that I'm using simple API key :
Exception in thread "main"
com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized
{
"code" : 401,
"errors" : [ {
"domain" : "global",
"location" : "Authorization",
"locationType" : "header",
"message" : "Login Required",
"reason" : "required"
} ],
"message" : "Login Required"
}
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:146)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:321)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1065)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
Here is code :
Calendar calendar = new Calendar.Builder(GoogleNetHttpTransport.newTrustedTransport(),JSON_FACTORY,null).setApplicationName(APPLICATION_NAME)
.setGoogleClientRequestInitializer(new CalendarRequestInitializer(API_KEY))
.build();
List<CalendarListEntry> calendars = calendar.calendarList().list().execute().getItems();// getting exception here
Here is my dependencies related to google :
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.23.0</version>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-calendar</artifactId>
<version>v3-rev305-1.23.0</version>
</dependency>
API key was create by the following guide :
https://docs.simplecalendar.io/google-api-key/
401 means invalid authorization header.
The access token you're using is either expired or invalid.
{
"error": {
"errors": [
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization",
}
],
"code": 401,
"message": "Invalid Credentials"
}
}
Try to do the following:
Get a new access token using the long-lived refresh token.
If this fails, direct the user through the OAuth flow, as described in Authorizing requests with OAuth 2.0.
If you are seeing this for a service account, check that you have successfully completed all the steps in the service account page.
You are passing null credentials as the 3rd parameter in Calendar.Builder
That's why you are getting 401.
Wanted to access files there in Bitbucket from java code. Is there any way to access bitbucket from code.
Yes, there is, checkout the documentation link, Bellow just a preview
You can list files
https://api.bitbucket.org/1.0/repositories/{accountname}/{repo_slug}/src/{revision}/{path}
Or get a file raw content
https://api.bitbucket.org/1.0/repositories/{accountname}/{repo_slug}/raw/{revision}/{path}
Update - 2018-01-04
Based in this article you can use Basic Authentication or oAuth (recommended by Atlassian), as the Basic Authentication is more simple to do then here a full Basic Authentication sample:
$ curl -i https://ElvisDeFreitas:myVerySecretPassword#api.bitbucket.org/1.0/repositories/ElvisDeFreitas/jna-examples/src/4bd1a0f584af/src/main/java/nativeapi/jna/syscall
HTTP/1.1 200 OK
Server: nginx
Vary: Authorization
Content-Type: application/json; charset=utf-8
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
Date: Thu, 04 Jan 2018 09:38:27 GMT
X-Served-By: app-142
ETag: "3414c377599e4dc02df7b370ffc557b5"
X-Static-Version: 2cd31fe906e9
X-Content-Type-Options: nosniff
X-Accepted-OAuth-Scopes: repository
X-Credential-Type: password
X-Render-Time: 0.156632900238
Connection: keep-alive
X-Request-Count: 300
X-Version: 2cd31fe906e9
X-Frame-Options: SAMEORIGIN
Content-Length: 668
{
"node": "4bd1a0f584af",
"path": "src/main/java/nativeapi/jna/syscall/",
"directories": [],
"files": [
{
"size": 19248,
"path": "src/main/java/nativeapi/jna/syscall/BytesUtils.java",
"timestamp": "2016-10-18T19:09:06Z",
"utctimestamp": "2016-10-18 19:09:06+00:00",
"revision": "4bd1a0f584af"
},
{
"size": 723,
"path": "src/main/java/nativeapi/jna/syscall/HelloWorldJNA.java",
"timestamp": "2016-10-17T19:45:10Z",
"utctimestamp": "2016-10-17 19:45:10+00:00",
"revision": "40cd9622d67c"
},
{
"size": 611,
"path": "src/main/java/nativeapi/jna/syscall/TestJNA.java",
"timestamp": "2016-10-17T19:45:10Z",
"utctimestamp": "2016-10-17 19:45:10+00:00",
"revision": "40cd9622d67c"
}
]
}
I am building a Dockerised record-playback system to help me record websites, so I can design scrapers aginst a local version rather than the real thing. This means that I do not swamp a website with automated requests, and has the added advantage that I do not need to be connected to the web to work.
I have used the Java-based WireMock internally, which records from a queue of site scrapes using Wget. I am using the WireMock API to read various pieces information from the mappings it records.
However, I have spotted from a mapping response that domain information does not seem to be recorded (except where it is in response headers by accident). See the following response from __admin/mappings:
{
"result": {
"ok": true,
"list": [
{
"id": "794d609f-99b9-376d-b6b8-04dab161c023",
"uuid": "794d609f-99b9-376d-b6b8-04dab161c023",
"request": {
"url": "/robots.txt",
"method": "GET"
},
"response": {
"status": 404,
"bodyFileName": "body-robots.txt-j9qqJ.txt",
"headers": {
"Server": "nginx/1.0.15",
"Date": "Wed, 04 Jan 2017 21:04:40 GMT",
"Content-Type": "text/html",
"Connection": "keep-alive"
}
}
},
{
"id": "e246fac2-f9ad-3799-b7b7-066941408b8b",
"uuid": "e246fac2-f9ad-3799-b7b7-066941408b8b",
"request": {
"url": "/about/careers/",
"method": "GET"
},
"response": {
"status": 200,
"bodyFileName": "body-about-careers-GhVqy.txt",
"headers": {
"Server": "nginx/1.0.15",
"Date": "Wed, 04 Jan 2017 21:04:35 GMT",
"Content-Type": "text/html",
"Last-Modified": "Wed, 04 Jan 2017 12:52:12 GMT",
"Connection": "keep-alive",
"X-CACHE-URI": "/about/careers/",
"Accept-Ranges": "bytes"
}
}
},
{
"id": "def378f5-a93c-333e-9663-edcd30c936d7",
"uuid": "def378f5-a93c-333e-9663-edcd30c936d7",
"request": {
"url": "/about/careers/feed/",
"method": "GET"
},
"response": {
"status": 200,
"bodyFileName": "body-careers-feed-Fd2fO.xml",
"headers": {
"Server": "nginx/1.0.15",
"Date": "Wed, 04 Jan 2017 21:04:45 GMT",
"Content-Type": "application/rss+xml; charset=UTF-8",
"Transfer-Encoding": "chunked",
"Connection": "keep-alive",
"X-Powered-By": "PHP/5.3.3",
"Vary": "Cookie",
"X-Pingback": "http://www.example.com/xmlrpc.php",
"Last-Modified": "Thu, 06 Jun 2013 14:01:52 GMT",
"ETag": "\"765fc03186b121a764133349f8b716df\"",
"X-Robots-Tag": "noindex, follow",
"Link": "<http://www.example.com/?p=2680>; rel=shortlink",
"X-CACHE-URI": "null cache"
}
}
},
{
"id": "616ca6d7-6e57-4c10-8b57-f6f3dabc0930",
"uuid": "616ca6d7-6e57-4c10-8b57-f6f3dabc0930",
"request": {
"method": "ANY"
},
"response": {
"status": 200,
"proxyBaseUrl": "http://www.example.com"
},
"priority": 10
}
]
}
}
The only clear recording of a URL is in the final entry against proxyBaseUrl, and given that I had to specify a URL in the console call I am now worried that if I record against a different domain, the domain that each one is from will be lost.
That would mean that in playback mode, WireMock would only be able to play back from one domain, and I'd have to restart it and point it to another cache in order to play back different sites. This is not workable for my use case, so is there a way around this problem?
(I have done a little work with Mountebank, and would be willing to switch to it, though I find WireMock generally easier to use. My limited understanding of Mountebank is that it suffers from the same single-domain problem, though I am happy to be corrected on that. I'd be happy to swap to any robust open-source API-driven recorder HTTP proxy, if dropping WireMock is the only way forward).
It's possible to serve WireMock stubs for multiple domains by adding a Host header criterion in your requests. Assuming your DNS/host file maps all the relevant domains to your WireMock server's IP, then this will cause it to behave like virtual hosting on an ordinary web server.
The main issue is that the recorder won't add the host header to your mappings so you'd need to do this yourself afterwards, or hack the recorder to do it on the fly.
I've been considering adding better support for this, so watch this space.
I'd also suggest checking out Hoverfly, which seems to solve this problem pretty well already.
I am using Twilio Rest API to get detail about participant using the participant call sid by sending request to/2010-04-01/Accounts/{AccountSid}/Calls/{ParticipantCallSid}.
In response I can't find any parameter for getting conference call sid of participant. Can anyone suggest me some way to figure it out from participant call sid?
The Participants list resource is a subresource of a Conference instance resource.
Resource URI:
/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Participants/{CallSid}
You will find the first example here returning a representation of the participant with both a call_sid and conference_sid.
{
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"call_sid": "CA386025c9bf5d6052a1d1ea42b4d16662",
"conference_sid": "CFbbe46ff1274e283f7e3ac1df0072ab39",
"date_created": "Wed, 18 Aug 2010 20:20:10 +0000",
"date_updated": "Wed, 18 Aug 2010 20:20:10 +0000",
"end_conference_on_exit": true,
"muted": false,
"start_conference_on_enter": true,
"uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Conferences/CFbbe46ff1274e283f7e3ac1df0072ab39/Participants/CA386025c9bf5d6052a1d1ea42b4d16662.json"
}
We are using the spring data elasticsearch library to query our elasticsearch server. We are currently using a rest call to get the results and have been successful, but we want to use the library.
The working rest query we are sending resembles
{
"query": {
"bool": {
"must": [
{ "range" : { "startDateTime" : { "from" : "2016-01-31T00:00:00", "to" : "2016-02-01T00:00:00" }}},
{ "match_phrase" : { "keyword" : "task" }}
]
}
}
}
Using the spring data elasicsearch query derivation tool we created the method
findMessagesByKeywordAndStartDateTimeBetween(String keyword, String start, String end);
Which derives to the query
{
"from": 0,
"query": {
"bool": {
"must": [
{"query_string":{"query":"\"tasks\"","fields":["keyword"]}},
{"range":{"startDateTime":{"from":"2016-01-31T00:00:00","to":"2016-02-01T00:00:00","include_lower":true,"include_upper":true}}}
]
}
}
}
I can run this query in a rest client and receive data, however, when the library attempts to query the database, I receive an error
{
"timestamp": 1454360466934,
"status": 500,
"error": "Internal Server Error",
"exception": "org.elasticsearch.action.search.SearchPhaseExecutionException",
"message": "Failed to execute phase [query_fetch], all shards failed; shardFailures {
[██████████████████████][████████████][0]: RemoteTransportException[
[██████-██-███-███████][inet[/██.███.███.███:9300]]
[indices:data/read/search[phase/query+fetch]]]; nested: SearchParseException[
[████████████][0]: from[0],size[10]: Parse Failure [
Failed to parse source [
{\"from\":0,\"size\":10,\"query\":{\"bool\":{\"must\":[{\"query_string\":{\"query\":\"\"/tasks\"\",\"fields\":[\"method\"]}},{\"range\":{\"startDateTime\":{\"from\":\"2016-01-31T00:00:00.000Z\",\"to\":\"2016-02-01T00:00:00.000Z\",\"include_lower\":true,\"include_upper\":true}}}]}}}
]
]
];
nested: NumberFormatException[For input string: \"2016-01-31T00:00:00.000Z\"];
}",
"path": "/report/tasks"
}
This leads us to believe that the date we are asking for is not in the correct format to reference against database items, but a sample result looks like
{
"_index": "████████████",
"_type": "████████████",
"_id": "████████████",
"_score": 0.000,
"_source": {
"keyword": "tasks",
"endDateTime": "2016-01-15T00:57:31.427Z",
"startDateTime": "2016-01-15T00:57:30.201Z",
"#timestamp": "2016-01-15T00:57:31+00:00",
"responseBody": "{...stuff goes here...}"
}
},...
So you would think that you would be able to query using that format.
We decided to attempt to get all results with the tasks keyword using a new query
findMessagesByKeyword(String keyword);
which derives to
{
"from": 0,
"query": {
"bool": {
"must": [
{"query_string":{"query":"\"tasks\"","fields":["keyword"]}}
]
}
}
}
This returns all the results in a page and after printing the mapped objects startDateTime and responseBody fields to the console
10: [
[Thu Oct 15 18:55:53 EDT 2015, {...stuff goes here...}]
[Thu Oct 15 18:56:38 EDT 2015, {...stuff goes here...}]
[Thu Oct 15 18:56:49 EDT 2015, {...stuff goes here...}]
[Thu Oct 15 18:58:59 EDT 2015, {...stuff goes here...}]
[Thu Oct 15 18:59:16 EDT 2015, {...stuff goes here...}]
[Thu Oct 15 18:59:33 EDT 2015, {...stuff goes here...}]
[Thu Oct 15 18:59:54 EDT 2015, {...stuff goes here...}]
[Thu Oct 15 19:00:02 EDT 2015, {...stuff goes here...}]
[Thu Oct 15 19:00:02 EDT 2015, {...stuff goes here...}]
[Thu Oct 15 19:00:11 EDT 2015, {...stuff goes here...}]
] //These are paged results, there are results as recently as last week, just not in this page
I notice that the date time field is now in a different format, so I use the format
public String DATETIME_FORMAT = "EE MMM dd HH:mm:ss zz yyyy";
instead of
public String DATETIME_FORMAT = "yyyy-MM-dd'T'00:00:00.000'Z'";
and get the error
NumberFormatException[For input string: \"Sun Jan 31 00:00:00 EST 2016\"]
The mapping for the field, if that helps, is
"startDateTime": {
"type": "date",
"format": "dateOptionalTime"
},
We have tried many formats and datatypes. When we changed the format
to
yyyMMddHHmmss
We no longer receive the error, but get no results.
At this point we know we must be doing something wrong, but are not sure where to go. All help is greatly appreciated.
Feb 2, 2016 10:15AM
Thanks to #Richa: After converting the date to long (in milliseconds) the query seems to run, but there are no results returned.
This is run on the default timerange of from yesterday until today, and on a manual timerange of about 10 days which I know have about 300 records.
I am also able to verify using the current rest implementation that there is data, and I am able to use a rest client to triple check, but no data for spring data impl.
Thoughts?
I got this error in my project too.Got it resolved using Long datatype. The dynamic finder provided by spring Data which you are using is taking date argument in String. Convert date to milliseconds and pass date in Long. Use method as:
findMessagesByKeywordAndStartDateTimeBetween(String keyword, Long start, Long end);
Hope this helps.