I am trying to get all companies using below api
var companies = new Companies(api);
companies.getList(function (error, data) {
console.log(data);
console.log(error);
});
My app have all the permission still I am getting below error,
{"server_time":1586893220,"error":{"status":403,"code":403,"message":"This APP has no access to requested resource"}}
Please let me know what I am missing.
According to the documentation for List companies API, the API key must have the following permissions: "View the structure of your companies/teams", see section "Required key permissions".
Please, revisit your key and adjust the permissions accordingly.
Related
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!
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! :)
I'm trying to restrict my Lex Bot to only show results of a SQL Search that a certain User has access to. For example, if User A only has access to records that belong to User A, the Bot will not allow User A to search for records that belong to User B.
Right now, I've got my Bot set up on a website that I've hosted via AWS S3. The issue I'm facing right now is getting my user's login information from the parent page (the website I've set up in S3) and sending it to my Lex Bot (which I've embedded as an Iframe).
The login to the page is done via Google Login which saves an Access Token in my SQL Database. I'd like to know how I can send this access token to my Lex Bot so I can authenticate it via Lambda. (I've already got the Lambda portion done, just need to know how to get the message from the parent page. Ideally, this part happens before the User talks to the Bot, which means a postback message so the user cannot see this information)
Things I've tried:
- I've tried doing a separate lambda function to handle this part only but don't really know how to integrate it into the website.
- I've tried using event listeners but am not very sure if the message goes to the bot or just the IFrame.
Right now, I'm out of ideas and any help would be greatly appreciated.
I managed to finally do it by adding a Javascript function to post a message. It doesn't look very professional but it works.
function isBotMinimized() {
return $('.' + lexWebUi.options.containerClass)
.hasClass('lex-web-ui--minimize');
}
function sendMessage() {
return Promise.resolve()
.then(function () {
return !isBotMinimized() ||
lexWebUi.sendMessageToIframe({ event: 'toggleMinimizeUi' });
})
.then(function () {
return lexWebUi.sendMessageToIframe({ event: 'postText', message: "Welcome"});
})
.then(function () { console.log('message succesfully sent'); })
.catch(function (error) { console.error('error sending message ', error); });
}
I have an ASP.NET Core application with work & school account authentication as configured by Visual Studio 2015 Update 3. I'm trying to integrate Microsoft.Graph with my application. Specifically, I'm trying to obtain user information (name, department, mail, about me, etc.) from the currently logged in user.
Following the samples for previous versions of ASP.NET MVC, I managed to make the following code work.
var token = await GetAppTokenAsync(authStringMicrosoft, graphResourceId);
var authHelper = new AuthenticationHelper() { AccessToken = token };
var graphClient = new GraphServiceClient(authHelper);
var users1 = await graphClient.Users.Request().GetAsync();
var users2 = await graphClient.Users.Request().Select("mail,givenName,surname").GetAsync();
This code is placed on the OnTokenValidated callback of OpenIdConnectEvents within OpenIdConnectOptions, on my Startup class.
app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions {
// ...
Events = new OpenIdConnectEvents {
OnTokenValidated = async ctx => {
// right here
}
}
});
So far, both calls to Users work great, and the code retrieves me a list of users with the specified properties. However, whenever I try to get data from the Me property, I get an error, as described below.
User me = await graphClient.Me.Request().GetAsync();
Error:
Code: Request_ResourceNotFound
Message: Resource '65c4885a-b493-4b8d-861f-79f0b8c23ec4' does not exist
or one of its queried reference-property objects are not present.
Inner error
I don't get why am I getting this error. I have checked the permissions for the application in the Azure Management Portal, both for Windows Azure Active Directory and Microsoft Graph applications. As a test, I checked everything that is to check, and still get this error.
So, my question is: why I get this error? Do I need to add a different permission, do I need to include anything else?
Thank you in advance.
From the sample code, it looks like app token is used here. /me request is not valid in context where app token (obtained by client_credential flow) is used. It is valid only in the context of access token obtained by authorization code flow (also referred to as 3-legged flow). If you can share request-id header from the error response along with timestamp, I can confirm.
I use google-api-php-client library to access webmaster tools data. When I wanted to list sitemaps, it appeared Fatal error: Uncaught exception 'Google_Service_Exception'(403) User does not have sufficient permission for site. See also: https://support.google.com/webmasters/answer/2451999.'
I add the service account email address as a restrict user for my site, but error still exists.
Finally I find the answer:
A service account is not like a regular Google account. You cannot use it to access specific resources even if you give that specific address "access" to it. See here for the different ways you can authorize your requests to the Webmaster API.
For me the problem was not the actual permission, but the way the domain name is passed. Here is my Node.js example, but the same goes for PHP:
import {JWT} from 'google-auth-library';
const client = new JWT(
null,
'service-account.json',
null,
['https://www.googleapis.com/auth/webmasters.readonly'],
);
const res = await client.request({
url: 'https://www.googleapis.com/webmasters/v3/sites/sc-domain:yourdomain.com/searchAnalytics/query',
method: 'POST',
data: {
"startDate": "2020-04-01",
"endDate": "2020-05-01",
"dimensions": ["country", "device"]
}
});
console.log(res.data);
Notice the syntax sc-domain:yourdomain.com. Passing 'yourdomain.com' will result in the error User does not have sufficient permission for site yourdomain.com.
Make sure you added the service-account email as user in search console: https://search.google.com/search-console/users
A service account is not like a regular Google account. You cannot use it to access specific resources even if you give that specific address "access" to it.
You need to manage the service permissions via Webmaster Admin. Add your service account
whatever#developer.gserviceaccount.com
there.