I am using Google APIs to perform various operations on my contacts. I wanted to add a contact to my contact list for this I used:
POST:
https://www.google.com/m8/feeds/contacts/default/thin?alt=json&max-results=500&v=3.0
With the header
Authorization: Bearer "access_token"
Content-Type: application/json
data:{title: "BATMAN", phonenumber: "3333", email:"tdk#gmail.com"}
The get the response alright:
HTTP/1.1 201 Created
This response was recorded by both Google OAuth 2.0 playground as well as Postman.
However when I wish to fetch the contact it is nowhere to be found. To fetch I my request is:
GET:
https://www.google.com/m8/feeds/contacts/default/thin?alt=json&max-results=500&v=3.0
With the header
Authorization: Bearer "access_token"
I get all contacts but the one just created. Would like to know where I'm going wrong?
Related
I am trying to get the media_id for a media upload. See docs here.
When using postman, my request is processed successfully and I get a response like this:
{
"media_id": 1222234872222222401,
"media_id_string": "1222734822222102201",
"expires_after_secs": 86399
}
Unfortunately, using postman for our app is not an option. However, when I post a tweet with just text, the tweet is posted successfully using our own native code. I have also recreated the request from postman, and can successfully recreated the same oauth_signature needed for the media upload authorization. So I know that the backend is working in that I can create valid credentials, but I think I need some help structuring the POST request itself.
Here is the code (Lucee ColdFusion):
mediaEndpoint = "https://upload.twitter.com/1.1/media/upload.json?command=INIT&total_bytes=10240&media_type=image/jpg&oauth_consumer_key=consumerKeyHere&oauth_token=tokenHere&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1653075352&oauth_nonce=UU5V18WLaPN&oauth_version=1.0&oauth_signature=verifiedSignature";
cfhttp(url=mediaEndpoint, method="POST", result="init") {
cfhttpparam(type="header", name="Content-Type", value="application/x-www-form-urlencoded");
cfhttpparam(type="header", name="Accepts", value="*/*");
cfhttpparam(type="header", name="Accept-Encoding", value="gzip, deflate, br");
cfhttpparam(type="header", name="Connection", value="keep-alive");
cfhttpparam(type="body", value="command=INIT&media_type=#mediaParameters.media_type#&total_bytes=#mediaParameters.total_bytes#");
}
But I keep getting the following 401:
{"errors":[{"code":32,"message":"Could not authenticate you."}]}
I believe you're supposed to send your authorization token in the header. You're sending it in the URL as a query string. Twitter's documentation would indicate you need to include an authorization header as such:
cfhttpparam(type="header", name="Authorization", value="Bearer: #YourAccessToken#");
When I try to call:
POST /oauth2/v1/tokens/bearer?grant_type=authorization_code&code=XXX&redirect_uri=https://developer.intuit.com/v2/OAuth2Playground/RedirectUrl
Content-Type: application/x-www-form-urlencoded
Accept: application/json
Authorization: Basic XXX
I get Status: 400 Code: InvalidFieldFormat Type:SYSTEM from every platform (curl, postman, mongodb stitch). The only place where it works is the intuit playground.
I do not see what is invalid.
You're trying to pass everything via a query string, and you should be passing it in the POST body.
You should be POSTing to this URL: https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer
And passing in a HTTP request body like this:
grant_type=authorization_code&
code=L3114709614564VSU8JSEiPkXx1xhV8D9mv4xbv6sZJycibMUI&
redirect_uri=https://www.mydemoapp.com/oauth-redirect
It's the POST body, not the query string.
This is documented on Intuit's site here:
https://developer.intuit.com/app/developer/qbo/docs/develop/authentication-and-authorization/oauth-2.0#step-5-exchange-authorization-code-for-refresh-and-access-tokens
I'm getting a 401 when trying to POST a request to the Twilio REST API.
I've included the following header:
Authorization: Basic <base64 encoded '<accountSid>:<authToken>' string>
And I've also tried Basic Authorization without encoding the string but the result is the same.
Edit: This is the response body:
Not Authorized - only signed requests from Twilio are allowed. More info about this error at: https://www.twilio.com/help/faq/twilio-basics/why-does-my-twiml-bin-url-give-me-a-not-authorized-error-when-i-try-to-view-it
How do i sign a request? The docs aren't very clear about it.
I'm at a loss for what's wrong. I'm always getting com.google.gdata.client.GoogleService$SessionExpiredException: Token invalid Token invalid when making API requests.
I have the following flow:
link user account
use credentials to get video upload entries
The code I use to link the user (get permission for my application) uses the JdoDataStoreFactory to persist user tokens and refresh info between API calls.
I used the following scopes when I ask the user to authorize my apps:
https://www.googleapis.com/auth/youtube.upload
https://www.googleapis.com/auth/youtube.readonly
Using GoogleAuthorizationCodeFlow I do a loadCredentials passing in the userId from my application that I used when requesting their auth token. I then feed those credentials to YouTubeService's getFeed method, requesting the url for video feeds: http://gdata.youtube.com/feeds/api/users/default/uploads
It looks like this:
service.setOAuth2Credentials(credentials)
videoFeed = service.getFeed(new URL(USER_FEED_PREFIX + DEFAULT_USER
+ UPLOADS_FEED_SUFFIX), VideoFeed.class)
After this executes, I always get the stacktrace:
com.google.gdata.client.GoogleService$SessionExpiredException: Token
invalid Token invalid Token invalid Error
401
at
com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:570)
at
com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:560)
at
com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:538)
at
com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:536)
at com.google.gdata.client.Service.getFeed(Service.java:1135) at
com.google.gdata.client.Service.getFeed(Service.java:998) at
com.google.gdata.client.GoogleService.getFeed(GoogleService.java:645)
at com.google.gdata.client.Service.getFeed(Service.java:1017)
The way I'm initiating my request to my service is via curl, my command looks like this:
curl http://localhost:8080/user/someUserId/content
Using Wireshark I see the following in my request:
GET /feeds/api/users/default/uploads HTTP/1.1
Authorization: Bearer <the_auth_token_for_the_user>
User-Agent: MyApp YouTube-Java/1.0 GData-Java/null(gzip)
X-GData-Client: MyApp
Accept-Encoding: gzip
GData-Version: 2.0
Cache-Control: no-cache
Pragma: no-cache
Host: gdata.youtube.com
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
I'm stuck.
Ok, I figured this out. I was trying to query the user's uploaded videos, and apparently for an app to do that it has to be authorized for the https://www.googleapis.com/auth/youtube scope, not the scopes I had configured
I have an application that creates and uploads videos for customers. Before attempting the upload the customer grants authorization and the resulting access and refresh tokens are saved. It sometimes happens that the customer does not have a YouTube channel associated with their Google Account. I detect this and create a channel for them. This normally works fine. But not always. Here's an example of where creating the channel failed:
Obtaining access token for Customer
post https://accounts.google.com/o/oauth2/token
HTTP Response: 200
{
"access_token" : "_new_access_token_",
"token_type" : "Bearer",
"expires_in" : 3600
}
Uploading video '_video_name_' for Customer
post http://uploads.gdata.youtube.com/feeds/api/users/default/uploads
Authorization: Bearer _new_access_token_
GData-Version: 2.1
X-GData-Key: key=_GData_Key_
Slug: n3n1xs.mp4
Content-Type: multipart/related; boundary="51d366cb05b71"
Content-Length: 255958407
Connection: close
HTTP Response: 403
<?xml version='1.0' encoding='UTF-8'?><errors><error><domain>yt:service</domain><code>youtube_signup_required</code></error></errors>
Obtaining channel names for Customer
get https://gdata.youtube.com/feeds/api/suggest/username?hint=CustomerNameVT&fields=entry%2Ftitle
GData-Version: 2.1
X-GData-Key: key=_GData_Key_
HTTP Response: 200
<?xml version='1.0' encoding='UTF-8'?><feed xmlns='http://www.w3.org/2005/Atom'><entry><title>CustomerNameVT</title></entry><entry><title>VTCustomerName</title></entry><entry><title>VTNameCustomer</title></entry><entry><title>CustomerVTName</title></entry><entry><title>CustomerNameVT1</title></entry><entry><title>NameCustomerVT</title></entry><entry><title>NameVTCustomer</title></entry></feed>
Linking YT channel for Customer (CustomerNameVT)
put https://gdata.youtube.com/feeds/api/users/default
Authorization: Bearer _new_access_token_
Content-Type: application/atom+xml
GData-Version: 2.1
X-GData-Key: key=_GData_Key_
<entry xmlns='http://www.w3.org/2005/Atom' xmlns:yt='http://gdata.youtube.com/schemas/2007'><yt:username>CustomerNameVT</yt:username></entry>
HTTP Response: 403
<errors xmlns='http://schemas.google.com/g/2005'><error><domain>GData</domain><code>ServiceForbiddenException</code><internalReason>Forbidden</internalReason></error></errors>
Notice that the requested name is the first one suggested by the suggest username api. As far as I can see this should work. It usually does. What's wrong this time?
The API for linking a Google Account to a new channel is deprecated.
Our current recommendation is to explicitly take users through a web-based linking process, starting at https://youtube.com/create_channel (or the m.youtube.com equivalent).