Google People API gapi.client.people is undefined - google-api

After I init the google people api gapi.client like so:
gapi.client.init with object containing the scope, api key, and client id:
init_people_api = async () => {
await gapi.client.init({
apiKey: API_KEY,
clientId: CLIENT_ID,
scope: "https://www.googleapis.com/auth/contacts",
})
await gapi.client.people.people.connections.list({
'resourceName': 'people/me',
'pageSize': 10,
'personFields': 'names,emailAddresses',
}).then(function(response) {
console.log(response)
})
}
When I call gapi.client.people, it is undefined.
gapi.client gives me this object:
Can anyone help me figure out how to debug this? Im doing what the tutorial indicates to do. My user is authenticated, I have waited for the api library to load, waited for gapi.client to initialize, but now when I ask for the gapi.client.people, nothing is there. How can I load this function?

You need to set the discoveryDocs parameter to People API discovery doc ["https://www.googleapis.com/discovery/v1/apis/people/v1/rest"] in order to get the People API loaded in GAPI. Please look at the documentation sample for an example of how to do this.

I seem to get the same problem when my API key is invalid. Make sure that you're creating and using a separate API key and not accidentally using the client secret instead. Also, double check that your API key isn't restricted in any way in the its settings.
If you don't find any problems there, try regenerating your API key or making a new one. Let me know if you're still running into this problem! :)

Related

Google Calendar Unable to Update Events

I had my Google calendar application almost working, I am still able to list all the events on the Primary Calendar and I can edit on Google and see the updated results on my calendar.
The problem is that my:
var eventToUpdate = gapi.client.calendar.events.get({
is getting an error 404.
From what I've been reading people who have had this issue previously were sending the wrong Key or wrong Event ID. But I've tested the values using
https://developers.google.com/calendar/v3/reference/events/update
& I get a success 200 back from Google.
Here is my event drop:
eventDrop: function( eventDropInfo ) {
gapi.auth.setToken('<?php echo $google_auth['access_token']; ?>');
handleAuthClick;
gapi.client.init({
apiKey: API_KEY,
clientId: CLIENT_ID,
discoveryDocs: DISCOVERY_DOCS,
scope: SCOPES
}).then(function () {
}, function(error) {
appendPre(JSON.stringify(error, null, 2));
});
updateSigninStatus(gapi.auth2.getAuthInstance().isSignedIn.get());
var eventToUpdate = gapi.client.calendar.events.get({
"calendarId": 'primary',
"eventId": eventDropInfo.id
});
There's more but that's the main Google APIs part.
I thought it could be the Key, however the Key works to grab the calendar information and is able to be used for my other Google stuff. (Drive, Login etc.)
I thought maybee it was the wrong calendar ID but using the Google "Try This API" It seems the Calendar ID + Event ID is perfect as Google gives me success.
Below you can see the console error, apologies if I've missed off anything important.
Thank You!
Error 404 From Console
--- Updated with more info
This shows Google References accepting the event ID and updating the event
This is the data I've entered to get the 200 success above
This is the URL showing the JSON google print out
Just to note, I've checked the scopes and the 2 I am using are:
var SCOPES = "https://www.googleapis.com/auth/calendar https://www.googleapis.com/auth/calendar.events";
The only others I can find are Read Only so I doubt it's the scopes.
Also the code seems to work as the only error I see is Google giving a 404, the loading of the events and calendar work it's just update that gives the 404.
As you can see through the screenshots I've updated the event ID i'm using to test is the same in my code as in the References test.
This is now working.
The problem was with my script not setting the OAuth Token correctly. It was saving the full JSON string instead of just the token.
After amending the login and getting the correct OAuth it works as it should :)
Thanks for the help!

Ruby on rails: Google API dailyLimitExceededUnreg

Hey guys I have an error when getting some tokens from google. Do you have any ideas about this error? And let me know how I can solve this error.
[{"domain"=>"usageLimits", "reason"=>"dailyLimitExceededUnreg", "message"=>"Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.", "extendedHelp"=>"https://code.google.com/apis/console"}], "code"=>403, "message"=>"Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."}}
My fetching code:
def self.request_tokens(code)
Request.post('https://www.googleapis.com/oauth2/v4/token', {
client_id: 'XXXXXXXXXXXXXX',
client_secret: 'XXXXXXXXXXXXXX',
redirect_uri: 'http://localhost:8080',
grant_type: 'authorization_code',
code: code,
})
end
def self.request_profile(access_token)
Request.get("https://www.googleapis.com/plus/v1/people/me?access_token=#{access_token}")[:body]
end
Add:
I have already added API key like this.
def self.request_profile(access_token)
  # Add api key but failed
Request.get("https://www.googleapis.com/plus/v1/people/me?access_token=#{access_token}?key=XXXXXXXXXXXXX")[:body]
  # try like this but failed
plus = Google::Apis::PlusV1::PlusService.new
plus.key = 'XXXXXXXXXXXXX'
plus.authorization = access_token
end
It means exactly what it says. You're overusing Google's API, so they're not letting you use it for the rest of the day unless you sign up for an API key. https://code.google.com/apis/console, the link in your error, will let you do that.
"Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
Means that you are trying to access a Google api without being authenticated or using an api key (using a valid client). In order to access all google apis you must have created a project on Google developer console. If you are accessing public data you can use an api key if you are accessing private user data you will need to use Oauth2.
You appear to have tried to set the client id in your code. The issue is that its not being applied properly to your request. I am not a ruby dev so can not assist you in debugging your code how ever google has a number of ruby tutorials OAuth 2.0
as well as use api key
require 'google/apis/plus_v1'
plus = Google::Apis::PlusV1::PlusService.new
plus.key = 'api_key'

The requested application with ID xxxxxx was not found

I 'm trying to post/get score from google play leaderboards
I met all the meta-tag from the documentation including my client id
<meta name="google-signin-client_id" content="XXXXXX-YYYYYYYYYYY.apps.googleusercontent.com" />
I also have setup the google sign-in system and all is fine, however when I try to call the leaderboards API I get the message error: The requested application with ID xxxxxx was not found
I am calling the API like the mentioned in the doc
gapi.client.request({
path: '/games/v1/leaderboards/LEADERBOARD-ID',
params: { maxResults: 3 },
callback: function(response) {
console.log(response);
}
});
I am not sure if the problem is the missing argument to execute a request.
Try to use this API requests method.
gapi.client.Request
An object encapsulating an HTTP request. This object is not
instantiated directly, rather it is returned by gapi.client.request.
There are two ways to execute a request. We recommend that you treat
the object as a promise and use the then method, but you can also use
the execute method and pass in a callback.
You can refer to this Github post for additional reference.
This message: W/AchievementAgent( 3558):
{"code":404,"errors":[{"message":"The requested application with ID
571707973781 was not found.","domain":"global","reason":"notFound "}]}
is a little cryptic but points to a mismatch with the auth
configuration on the console and the application.
You'll want to double check the keystore SHA1 fingerprint of the
keystore you signed the app with and the one configured in the dev
console.
It could also be the bundle ID, but that is hard to mess up since it
is part of the resource data used when running Setup for the plugin.
Also, it could be that the player is not a tester for this game.
For anyone having the same issue, you need to publish the beta version of the game to be able to interact with the game scoreboard.
Note: In the beta version, only tester accounts added to the game can access the scoreboard.

Get token by gapi

I followed this link and made a test page of google login by gapi. It worked, and did return the profile details.
Previously, I had tried this appraoch by passport.js, but because of the fragment problem, I did not manage to make it work.
In the passportjs appraoch, we could get a token. Does anyone know how we could get a token by gapi?
Additionally, does anyone know why we don't need to specify a secret in the code of gapi?
You can get the token in the AuthResponse.
You do need an API key for gapi too:
gapi.client.init({
'apiKey': 'YOUR_API_KEY',
...
})

Spring Social .NET OAuth confusion

I had originally posted a question about what API to use in regards to making a SharePoint 2010 timer job able to access the twitter API and chose the Spring Social .NET api and have run into another roadblock.
I cannot get the OAuth handshake or 'dance' to work.
I have the consumer key and secret linked to my account, as well as an access token and secret, but any time I try to initialize a TwitterServiceProvider object, any time I attempt to query I get a 401 error.
The console/mvc and wp7.1 examples provided dont give much insight how I can get this code (which should run with no human involvement) to work.
Does anyone have any good resources regarding this?
Thanks in advance
If you already have access token value and secret, you can do something like that:
ITwitter twitter = new TwitterTemplate("consumerKey", "consumerSecret", "accessTokenValue", "accessTokenSecret");
// twitterApi.UserOperations.GetUserProfile();
that is equivalent to :
TwitterServiceProvider serviceProvider = new TwitterServiceProvider("consumerKey", "consumerSecret");
ITwitter twitterApi = serviceProvider.GetApi("accessTokenValue", "accessTokenSecret");
// twitterApi.UserOperations.GetUserProfile();
How do you get the access token secret and value?

Resources