Issue with Google Analytics API - rest

I am trying to use the REST web services API from Google (Analytics) and I am getting a meaningless response instead of the expected data from Google Analytics.
Here is my request and the corresponding response:
GET /auth/analytics.readonly?ids=ga:12660456&start-date=2012-01-01&end-date=2012-02-02&metrics=ga:visits HTTP/1.1
Host: www.googleapis.com
Authorization: OAuth ya29.mytokenhere
HTTP/1.1 200 OK
status: 200
content-length: 18
x-xss-protection: 1; mode=block
content-location: https://www.googleapis.com/auth/analytics.readonly?ids=ga:12660456&start-date=2012-01-01&end-date=2012-02-02&metrics=ga:visits
x-content-type-options: nosniff
x-google-cache-control: remote-fetch
expires: Mon, 21 May 2012 19:52:57 GMT
server: GSE
via: HTTP/1.1 GWA
cache-control: private, max-age=0
date: Mon, 21 May 2012 19:52:57 GMT
x-frame-options: SAMEORIGIN
content-type: text/plain
-content-encoding: gzip
analytics.readonly
Can anyone please help?
Regards,

OAuth isn't performed by requesting the auth scope URL, like you seem to be doing. The only reason the Google's auth scopes are URLs at all are (AFAIK) so that they can be guaranteed to be globally unique.
More details about how to do OAuth 2.0 with Google here: https://developers.google.com/accounts/docs/OAuth2

Related

Twitter API 1.1 returns an Authentication Error (Error 32) when sending the INIT command to start the video upload process

I am trying to upload a video to Twitter using the chunked upload endpoint. For this I post to the endpoint '**https://upload.twitter.com/1.1/media/upload.json**' the 'INIT' command. n posting to the Twitter server I get the error below
{"errors":[{"code":32,"message":"Could not authenticate you."}]}
At first I had a doubt regarding the Oauth signature generation function. But I can post a tweet and upload a .png image to the https://upload.twitter.com/1.1/media/upload.json using the Oauth signature generated by this Oauth signature generation function
I could also post the 'INIT' command initiate the chunked upload of a video successfully using TWURL
I have pasted below the actual request and response which was captured using Fiddler
Request
POST https://upload.twitter.com/1.1/media/upload.json HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Host: upload.twitter.com
Authorization: OAuth oauth_consumer_key="", oauth_nonce="MDAwMDAwMDAtMDAwMC0wMDAwLTAwMDAtMDAwMDAwMDAwMDAw", oauth_signature_method="HMAC-SHA1", oauth_signature="BtxgmRxA1bt5FI2Hu3qhhVIb5Eg%3D", oauth_timestamp="1607577817", oauth_token="****", oauth_version="1.0"
Content-Length: 357
Connection: Keep-Alive
command=INIT&media_category=tweetvideo&media_type=video%252Fmp4&oauth_consumer_key=******&oauth_nonce=MDAwMDAwMDAtMDAwMC0wMDAwLTAwMDAtMDAwMDAwMDAwMDAw&oauth_signature=BtxgmRxA1bt5FI2Hu3qhhVIb5Eg%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1607577817&oauth_token=********&oauth_version=1.0
Response
HTTP/1.1 401 Authorization Required
cache-control: no-cache, no-store, max-age=0
content-length: 64
content-type: application/json; charset=utf-8
date: Thu, 10 Dec 2020 05:23:39 GMT
server: tsa_k
set-cookie: personalization_id="v1_jQ8zK7e0TgY2uCQKkiVOgA=="; Max-Age=63072000; Expires=Sat, 10 Dec 2022 05:23:39 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None
set-cookie: guest_id=v1%3A160757781933882195; Max-Age=63072000; Expires=Sat, 10 Dec 2022 05:23:39 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None
strict-transport-security: max-age=631138519
vary: Origin
x-connection-hash: 0e6ebd96e051b8f7a413fb79c51a8f42
x-frame-options: SAMEORIGIN
x-response-time: 182
x-tsa-request-body-time: 0
x-xss-protection: 1; mode=block
{"errors":[{"code":32,"message":"Could not authenticate you."}]}
i googled a lot for a solution to this issue but none of the solutions are working. I also read the relevant Twitter documentation many many times
Thanks in advance for any tips
Mathew
Finally found what was causing the error. While passing the URL to which data has to be posted to the function that I use to generate the Oauth signature I was passing 'https://upload.twitter.com/1.1//media/update.json.com' instead of 'https://upload.twitter.com/1.1/media/update.json.com'. One additional '/' character was the reason why the error was occurring.
Thanks and regards
Mathew

Google My Business API - Response "Method not found" 404

Just got access to the Google My Business API and have been following the instructions found here: https://developers.google.com/my-business/content/get-started
Project Info
PROJECT_ID=twocents-reviews
PROJECT_NUMBER=705754565185
I'm trying to use the OAuth 2.0 Playground to send my first Google My Business API request to https://mybusiness.googleapis.com/v3/accounts, and this is the response I get (below).
Response
GET /v3/accounts HTTP/1.1
Host: mybusiness.googleapis.com
Content-length: 0
Authorization: Bearer [**** REDACTED ****]
HTTP/1.1 404 Not Found
Content-length: 100
X-xss-protection: 1; mode=block
X-content-type-options: nosniff
X-goog-trace-id: 6748d818415fd6349e9763a87acb707e
Transfer-encoding: chunked
Vary: Origin, X-Origin, Referer
Server: ESF
-content-encoding: gzip
Cache-control: private
Date: Fri, 19 Jan 2018 23:28:51 GMT
X-frame-options: SAMEORIGIN
Alt-svc: hq=":443"; ma=2592000; quic=51303431; quic=51303339; quic=51303338; quic=51303337; quic=51303335,quic=":443"; ma=2592000; v="41,39,38,37,35"
Content-type: application/json; charset=UTF-8
{
"error": {
"status": "NOT_FOUND",
"message": "Method not found.",
"code": 404
}
}
Any suggestions?
Google just hadn't finished the setup process yet. All I needed to do was wait a bit longer for the API to work for me.

ServiceAccout has empty calendarList after sharing a calendar has been shaired with it

On creating a new service account via Google Console, when then sharing a calendar with the service account, the calendar doesn't appear in the calendarList response for the authenticated service account.
This was working okay for some time but appears to have started failing more recently.
Oddly, if I delete the shared account entry on the calendar and then add it back in, it usually works. It doesn't appear to be a time delay as have waited hours initially and always zero results in the calendar list, until removing the shared account on the calendar and resharing.
The following are steps I've used to reproduce:
In Google Console web UI, create a new service account with 'Furnish a new private key' selected to download the JSON key.
In the Google Calendar web UI, go to calendar settings and 'Share this calendar', then share the calendar with the service account email, then save the changes.
In REST calls, authenticate with the JSON key with POST call to oauth2/v3/token
Send GET request for calendar/v3/users/me/calendarList
then optionally to show it working...
Delete the service account share from the calendar and save.
Add the service account email to the calendar share and save.
Repeat steps 2 and 3. This time it will probably work.
This is partially a manual process for our end users to create a service account and share calendars via Google web UI. Note I've been using additional calendars on my own Google account to share with the service account (this reflects our end user use case), rather than just the default calendar.
Client code is REST based. To provide an example I have shown the REST requests and responses below. There are simply two requests, one to authenticate and one to fetch the calendarList. These occur after the manual steps in the UI to create a service account and then share a calendar with that account.
---
Request:
POST https://www.googleapis.com/oauth2/v3/token HTTP/1.1
Accept: application/json, application/xml, text/json, text/x-json, text/javascript, text/xml
User-Agent: RestSharp/105.2.3.0
Content-Type: application/x-www-form-urlencoded
Host: www.googleapis.com
Content-Length: 758
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&assertion=[ASSERTION_JWT_HERE]
Response:
HTTP/1.1 200 OK
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: Mon, 01 Jan 1990 00:00:00 GMT
Date: Tue, 14 Mar 2017 20:17:18 GMT
Vary: Origin
Vary: X-Origin
Content-Type: application/json; charset=UTF-8
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Alt-Svc: quic=":443"; ma=2592000; v="36,35,34"
Content-Length: 197
{
"access_token": "ya29.ElkOBAzSOzE_J2VOGFeWnTAGXdtoadW2FbnGga99SrMeamL7j6KetKomvT4aoy4jsRCcXpK-N6sxRBLFUaj_kPWFin4m6xvg_CtaTtkG5tVc_IxS7IezJDf32g",
"token_type": "Bearer",
"expires_in": 3600
}
---
---
Request
GET https://www.googleapis.com/calendar/v3/users/me/calendarList?minAccessRole=reader HTTP/1.1
Authorization: Bearer ya29.ElkOBAzSOzE_J2VOGFeWnTAGXdtoadW2FbnGga99SrMeamL7j6KetKomvT4aoy4jsRCcXpK-N6sxRBLFUaj_kPWFin4m6xvg_CtaTtkG5tVc_IxS7IezJDf32g
Accept: application/json, application/xml, text/json, text/x-json, text/javascript, text/xml
User-Agent: RestSharp/105.2.3.0
Host: www.googleapis.com
Accept-Encoding: gzip, deflate
Response:
HTTP/1.1 200 OK
Expires: Tue, 14 Mar 2017 20:17:19 GMT
Date: Tue, 14 Mar 2017 20:17:19 GMT
Cache-Control: private, max-age=0, must-revalidate, no-transform
Vary: Origin
Vary: X-Origin
Content-Type: application/json; charset=UTF-8
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Content-Length: 202
Server: GSE
Alt-Svc: quic=":443"; ma=2592000; v="36,35,34"
{
"kind": "calendar#calendarList",
"etag": "\"p328bl14pt3bd40g\"",
"nextSyncToken": "CJC6hJno1tICEj10ZXN0MS05MjhAY2FsZW5kYXItY29ubmVjdG9yLS0tb25lbGFuLmlhbS5nc2VydmljZWFjY291bnQuY29t",
"items": []
}
---
Note, I haven't provided the actual JWT for the ouath request, but the authentication is working fine. Also note the calendar is shared as either read or modify with the service account. I can also query the calendar itself and fetch events using the service account, but it is querying the list of calendars associated with the account that fails.
Had also raised this as an issue here but posting this here also in case I'm missing something, although as said all this was working fine until more recently, and our existing unchanged client software has started failing with newly created service accounts.
When you share a calendar with someone VIA the google calendar website the code on the website automatically adds the calendar to the users calendar.list. All the calendarlist is the list on the bottom left of the google calendar website. A user can have access to a calendar without it being in their calendarlist.
When sharing a calendar wish a service account this does not always happen. None of the service accounts I have shared my calendars with have ever had anything in their calendarlist. If you need it to be in the calendarlist then you should have the service account insert it. Using CalendarList: insert just grab the calendar id in question off of the website.

facebook redirect_uri not working for mobile

I have a facebook canvas app and I'm running both the same code and same redirect_uri for web and mobile, it works without issue in my web configuration but my mobile version doesn't. My app is a responsive app, so even the URLs within the facebook configuration are identical.
The method I'm using for both to generate the url
List<NameValuePair> qparams = new ArrayList<>();
qparams.add(new BasicNameValuePair("client_id", facebookClientId));
qparams.add(new BasicNameValuePair("redirect_uri", "https://apps.facebook.com/customdomain"));
qparams.add(new BasicNameValuePair("client_secret", facebookClientSecret));
qparams.add(new BasicNameValuePair("code", code));
uri = new URIBuilder()
.setScheme("https")
.setHost("graph.facebook.com")
.setPath("/oauth/access_token")
.setParameters(qparams)
.build();
website url https://local.mydomain.com:8443/test/facebook/auth
mobile url https://local.mydomain.com:8443/test/facebook/auth
Canvas URL
https://local.mydomain.com:8443/test/facebook/auth/
auth urls
https://local.mydomain.com:8443/test/facebook/auth/
https://apps.facebook.com/customdomain
App domain
https://apps.facebook.com/customdomain
Working url from website
https://graph.facebook.com/oauth/access_token?client_id=578152068997908&redirect_uri=https%3A%2F%2Fapps.facebook.com%2Fmydomain&client_secret=xxxx&code=AQBQ_VZlxKWqMfmC2neu8DIllor0Lrp1wvLvtSD5do3PyMfO_jxiEjcGEbZ-a0bEJbe6Ya9Noh9esXm2mgmgw0zP9OQOM-2h7VBYkruix0o7isKWwYkksFAi-i2qpUmTBcb0YxAqrn5y2aEWk8GxmhEVAgsW3GGLksNTndhZr3NYDs5Mi4GtmsjMKJbO8dTzePDrh4iSz_Qv0fmgalkDhIRmM7zsjodFPkytL4rlzG9Q4oN14qEhpBUmISnu8cAQcLvOlYACD17nFqhyq-BOVmX8PpUNRFdoHDk9KUTUv7c8PbfVGOBmWeJJKxWdZ0ncUu0
Non working mobile
https://graph.facebook.com/oauth/access_token?client_id=578152068997908&redirect_uri=https%3A%2F%2Fapps.facebook.com%2Fmydomain&client_secret=xxxx&code=AQBQ_VZlxKWqMfmC2neu8DIllor0Lrp1wvLvtSD5do3PyMfO_jxiEjcGEbZ-a0bEJbe6Ya9Noh9esXm2mgmgw0zP9OQOM-2h7VBYkruix0o7isKWwYkksFAi-i2qpUmTBcb0YxAqrn5y2aEWk8GxmhEVAgsW3GGLksNTndhZr3NYDs5Mi4GtmsjMKJbO8dTzePDrh4iSz_Qv0fmgalkDhIRmM7zsjodFPkytL4rlzG9Q4oN14qEhpBUmISnu8cAQcLvOlYACD17nFqhyq-BOVmX8PpUNRFdoHDk9KUTUv7c8PbfVGOBmWeJJKxWdZ0ncUu0
Response
InternalModule.PageLoader Loaded page 'facebook/Auth' (en) in 112.543 ms
response HttpResponseProxy{HTTP/1.1 400 Bad Request [WWW-Authenticate: OAuth "Facebook Platform" "invalid_code" "Error validating verification code. Please make sure your redirect_uri is identical to the one you used in the OAuth dialog request", Facebook-API-Version: v1.0, Content-Type: text/javascript; charset=UTF-8, Pragma: no-cache, Access-Control-Allow-Origin: *, X-FB-Rev: 1514665, Cache-Control: no-store, Expires: Sat, 01 Jan 2000 00:00:00 GMT, X-FB-Debug: WpyeYYw/BIs08HkafBWcrkbU5tICVgEHTKrPBAiTzZEqjgP3OGCP8eQwNVx2lx6b0iH9GGqIrir3S4iGu7VAIw==, Date: Tue, 02 Dec 2014 09:21:50 GMT, Connection: keep-alive, Content-Length: 190]}
facebook.FacebookAuth com.mydomain.test.pages.facebook.FacebookAuth 400 HttpResponseProxy{HTTP/1.1 400 Bad Request [WWW-Authenticate: OAuth "Facebook Platform" "invalid_code" "Error validating verification code. Please make sure your redirect_uri is identical to the one you used in the OAuth dialog request", Facebook-API-Version: v1.0, Content-Type: text/javascript; charset=UTF-8, Pragma: no-cache, Access-Control-Allow-Origin: *, X-FB-Rev: 1514665, Cache-Control: no-store, Expires: Sat, 01 Jan 2000 00:00:00 GMT, X-FB-Debug: WpyeYYw/BIs08HkafBWcrkbU5tICVgEHTKrPBAiTzZEqjgP3OGCP8eQwNVx2lx6b0iH9GGqIrir3S4iGu7VAIw==, Date: Tue, 02 Dec 2014 09:21:50 GMT, Connection: keep-alive, Content-Length: 190]}
facebook.FacebookAuth com.mydomain.test.pages.facebook.FacebookAuth
What could possible be causing this issue? Does it have something to do with canvas and mobile?

How to search using Github API with enterprise

I'm trying to search through repositories, but I can't seem to figure it out with github enterprise edition. I have tried the following with no results. Any suggestions?
curl -i http://my.domain.com/api/v3/repositories "If-Modified-Since: Mon, 16 Jun 2014 01:01:01 CST"
curl -i http://my.domain.com/api/v3/search/repos?q=pushed:2014-06-17
HTTP/1.1 404 Not Found
Server: GitHub.com
Date: Wed, 18 Jun 2014 16:45:58 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Status: 404 Not Found
X-GitHub-Media-Type: github.beta
X-Content-Type-Options: nosniff
Content-Length: 29
Access-Control-Allow-Credentials: true
Access-Control-Expose-Headers: ETag, Link, X-RateLimit-Limit, X-RateLimit-Remaining, X- RateLimit-Res
et, X-OAuth-Scopes, X-Accepted-OAuth-Scopes
Access-Control-Allow-Origin: *
X-GitHub-Request-Id: b4eec0e7-1b1a-48b7-81d8-d63c28b55b37
{
"message": "Not Found"
}
One of the nice things of Github's API both public and Enterprise, is if you go to the API root, it will tell you what endpoints are available. On an enterprise instance it is: http://my.domain.com/api/v3/. Looking at my company's enterprise instance (sorry not sure of the version), I only see the legacy search API endpoints.
As a result: http://my.domain.com/api/v3/legacy/repos/search/pushed:2014-06-17 is likely the search URL you are wanting.