I'm trying to use the google-api-client gem to access the Google Search API for Shopping. Unfortunately, I can't seem to authenticate despite creating an access_token through the Google APIs Console.
Here is my code:
client = Google::APIClient.new
client.authorization.access_token = "<MY_CONSOLE_ACCESS_TOKEN>"
client.authorization.scope = "https://www.googleapis.com/auth/shoppingapi"
shopping = client.discovered_api("shopping", "v1")
response = client.execute(api_method: shopping.products.list,
parameters: { source: "public" })
When I view response.data, I see an error message though:
#<Google::APIClient::Schema::Shopping::V1::Products:0x809d6e14 DATA:{"error"=>{"errors"=>[{"domain"=>"global", "reason"=>"authError", "message"=>"Invalid Credentials", "locationType"=>"header", "location"=>"Authorization"}], "code"=>401, "message"=>"Invalid Credentials"}}>
What am I doing wrong?
Of course I figure it out minutes after posting. I'll share what worked for anyone else who has the same question.
client = Google::APIClient.new(authorization: nil)
shopping = client.discovered_api("shopping", "v1")
response = client.execute(key: "<MY_ACCESS_TOKEN>",
api_method: shopping.products.list,
parameters: { source: "public", country: "US" })
Related
I am testing out Zoho desk API. I have set up a dummy client in zoho console dashboard and using the self client option to generate a oauth_token. However when I try to use it, it always return an error code 401 with error code "INVALID_OAUTH".
I have checked for characters, and using it before even one minute of generation. Can somebody please help me with this?
{
url = "https://desk.zoho.in/api/v1/organizations"
payload = ""
headers = {
'Authorization': "Zoho-oauthtoken 1000.XXXXXabdbd925112
4ff.44d3eccd1e1a03bd25db1016f0f13322"
}
}
Response
{
"errorCode": "INVALID_OAUTH",
"message": "The OAuth Token you provided is invalid."
}
I'm trying to consume the WP Rest API with Nativescript.
The WP API and the Authorization with OAUTH1 is already well setup and tested with POSTMAN.
Nativescript Login function to consume rest is already setup too and work without OAUTH.
Now I'm trying to Login with OAUTH here the code :
authorizationString = 'OAuth oauth_consumer_key="T2yXcbN28Ufj",
oauth_token="AmEVr5oSNmbKyZKccFjtmnSk",
oauth_signature_method="HMAC-SHA1",
oauth_timestamp="1492267438",
oauth_nonce="rGFJG2",
oauth_version="1.0",
oauth_signature="Ru%2BaSvsZn2liesd2ENy8GeNsdHY%3D"';
login(user: User){
console.log("Try to login User : " + user.email);
let headers = new Headers({"Authorization": authorizationString});
let body = JSON.stringify({
username: user.username,
email: user.email,
password: user.password
});
headers.append("Content-Type", this.contentType);
return this.http.post(
this.api,
body,
{headers: headers}
)
.map( response => response.json() )
.do(data => {
//Do work!!
})
.catch(this.handleErrors);
}
But i got an error, this error means the autorization is not well formatted or sent :
"data": {
"code": "rest_cannot_access",
"message": "Only authenticated users can access the REST API.",
"data": {
"status": 401
}
}
How to properly use oauth1 with Nativescript?
I just switched to OAUTH2 by using a opensource plugin :
https://github.com/wlcdesigns/WP-OAuth2-Server-Client
and it's more easy to use with the authorization : Bearer
I'm trying to get my GPS data from the Waze app using the rest-client lib. I'm basicly trying to fake a login via the website https://www.waze.com/. After login (you can use JohnDoeSpeedy228:gre#tStory92) when you visit https://www.waze.com/editor/, click on "Drives" after review the the network calls you'll get to see the raw JSON data.
I seem to have succesfully logged in but when making the request to return the list of all my drives it returns the following
{"users"=>{"objects"=>[]}, "archives"=>{"totalSessions"=>0, "objects"=>[]}}
It should return something like this:
{
"users":{
"objects":[
]
},
"archives":{
"totalSessions":1,
"objects":[
{
"id":<REDACTED>,
"userID":<REDACTED>,
"existingRoadMeters":2839,
"newRoadMeters":0,
"totalRoadMeters":2839,
"startTime":1456996197000,
"endTime":1456996636000,
"hasFullSession":true
}
]
}
}
Here's what I'm trying:
require 'rest-client'
require 'json'
GET_CSRF_URL = "https://www.waze.com/login/get"
SESSION_URL = "https://www.waze.com/login/create"
SESSION_LIST_URL = "https://www.waze.com/Descartes-live/app/Archive/List"
SESSON_DATA_URL = "https://www.waze.com/Descartes-live/app/Archive/Session"
AUTH = {'user_id'=>'JohnDoeSpeedy228','password'=>'gre#tStory92'}
req = RestClient.get(GET_CSRF_URL)
csrfhash = req.cookies
csrfhash['editor_env'] = 'row'
headers = {'X-CSRF-Token'=>csrfhash['_csrf_token']}
log = RestClient::Request.execute(
method: :post,
url: SESSION_URL,
cookies: csrfhash,
headers: headers,
payload: AUTH
)
ses = RestClient::Request.execute(
method: :get,
url: SESSION_LIST_URL,
cookies: log.cookies,
payload: {'minDistance'=>1000,'count'=>50, 'offset'=>0}
)
puts JSON.parse(ses)
Am I doing something wrong?
My guess is that you are confusing two accounts. Are you sure you logged a drive while logged in as JohnDoeSpeedy228? If there are no sessions from that user when logged into the site manually, I wouldn't expect the code to work either.
We can't find any of your drives.
Have you started driving with the Waze app yet? If so, please make sure you logged into the Map Editor with the same credentials you use in the app.
Android/iOS client sends to server API access_token and message.
I'm trying to share but with no luck, google responses with 'Invalid credentials'.
I was trying to add requestvisibleactions to client:
client = Google::APIClient.new(requestvisibleactions: ['https://schemas.google.com/AddActivity'])
And same to client.execute.
class GoogleSharer
def self.share(access_token, message, resource)
client = Google::APIClient.new
client.authorization.update_token!(access_token: access_token)
plus = client.discovered_api('plus', 'v1')
moment = {
type: ['http://schemas.google.com/AddActivity'],
target: { name: message, url: get_resource_url(resource) }
}
response = client.execute(api_method: plus.moments.insert, parameters: {collection: 'vault', userId: 'me'}, body_object: moment).body
a = 10
end
end
Please advise. Thanks.
I've registered my mobile app (Sencha Touch) with Twitter and I have the appropriate keys to access version 1.1 of the API. Now I'm writing a web service to provide the JSON back to my mobile app. Here is what I have so far based on the ruby example provided by Twitter on this page.
require 'oauth'
class Twitter
def initialize
#consumer_key = "omitted"
#consumer_secret = "omitted"
#access_token = "omitted"
#access_token_secret = "omitted"
end
def pull_tweets(query)
authorized_token = prepare_access_token(#access_token, #access_token_secret)
response = authorized_token.request(:get, query)
end
private
def prepare_access_token(oauth_token, oauth_token_secret)
consumer = OAuth::Consumer.new(#consumer_key, #consumer_secret, { site: "https://api.twitter.com/", scheme: :header })
token_hash = { oauth_token: oauth_token, oauth_token_secret: oauth_token_secret }
access_token = OAuth::AccessToken.from_hash(consumer, token_hash)
return access_token
end
end
query = "https://api.twitter.com/1.1/statuses/home_timeline.json"
response = Twitter.new.pull_tweets(query)
p response
When I run this code I get #<Net::HTTPBadRequest 400 Bad Request readbody=true> as a response. After doing some research I found that this could be one of four things.
My authentication details are wrong
I'm being rate limited
Ruby is not formatting the query string properly (more details)
The query I'm using is wrong
I don't think I'm being rate limited because I've never managed to get a response, and I don't know how to check if I'm authenticating properly. Any help is much appreciated.