I am using Big query sample code to work with big query. I am getting the following error while reading dataset list using the big query api.
The code is
Bigquery bigquery = Bigquery.builder(httpTransport, jsonFactory)
.setHttpRequestInitializer(requestInitializer)
.setJsonHttpRequestInitializer(new JsonHttpRequestInitializer() {
public void initialize(JsonHttpRequest request) {
BigqueryRequest bigqueryRequest = (BigqueryRequest) request;
bigqueryRequest.setPrettyPrint(true);
}
}).build();
Datasets.List datasetRequest = bigquery.datasets().list(PROJECT_ID);
DatasetList datasetList = datasetRequest.execute();
if (datasetList.getDatasets() != null) {
java.util.List datasets = datasetList.getDatasets();
for (Object dataset : datasets) {
System.out.format("%s\n", ((com.google.api.services.bigquery.model.DatasetList.Datasets)dataset).getDatasetReference().getDatasetId());
}
}
The exception is
Exception in thread "main" com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized
{
"code" : 401,
"errors" : [ {
"domain" : "global",
"location" : "Authorization",
"locationType" : "header",
"message" : "User is not a trusted tester",
"reason" : "authError"
} ],
"message" : "User is not a trusted tester"
}
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:159)
at com.google.api.client.googleapis.json.GoogleJsonResponseException.execute(GoogleJsonResponseException.java:187)
at com.google.api.client.googleapis.services.GoogleClient.executeUnparsed(GoogleClient.java:115)
at com.google.api.client.http.json.JsonHttpRequest.executeUnparsed(JsonHttpRequest.java:112)
at com.google.api.services.bigquery.Bigquery$Datasets$List.execute(Bigquery.java:964)
at ShortSample.main(ShortSample.java:74
)
I don't see this as an authentication issue as I could use the same code to connect to Google Plus account via Google plus api. I also observed that api examples are stale.
Any Suggestions to fix it.
I suspect you're using an older version of the BigQuery Java client library that is based on a prerelease version of the API (v2beta1). If that's the case, try upgrading to the latest version of the client library here:
http://mavenrepo.google-api-java-client.googlecode.com/hg/com/google/apis/google-api-services-bigquery/v2-rev5-1.5.0-beta/
We'll make sure the links on the API client library page are updated, too!
I have encountered a similar problem and jcondit's solution works well for me (updating the jars). And for the authentication code, you may also take a look at here.
Related
I'm trying to search calendars by name with the v1.0/search/query endpoint from the Graph API. However even I'm trying the examples from the Explorer I get the following error:
{
"error": {
"code": "InternalServerError",
"message": "Invalid URI: The hostname could not be parsed.",
"innerError": {
"date": "2022-03-28T19:50:56",
"request-id": "ddb02afc-1c82-4884-d352-4a8d80809b20",
"client-request-id": "58147981-de34-ba11-ab1f-6e17dca603f9"
}
}
}
Graph Explorer:
Is this endpoint still supported? Is it not allowed for Applications?
From the output we can see that , in the tip its saying for adding the permissions for accessing Calendar events and its API's.
so please try to add those permissions and retry again. Please refer this DOC
I have an Express app which supports Google authentication and authorization via passport. I have begun integrating it with Google Assistant and things were going quite well but I am having trouble with the account linking as described at https://developers.google.com/actions/identity/google-sign-in#start_the_authentication_flow
Using the method in the docs at https://codelabs.developers.google.com/codelabs/actions-2/#4 I was able to get user details but when I try to modify to support
app.intent('Start Signin', conv => {
conv.ask(new SignIn('To get your account details'))
})
and
app.intent('Get Signin', (conv, params, signin) => { ...}
the dialogflow always falls back to my default fallback intent and I get an error in Express console
Error: Dialogflow IntentHandler not found for intent: Default Fallback Intent
My dialogflow intent is set to use webhook and other intents work fine (until I add these sign-in intents!)
Reading this thread Dialogflow IntentHandler not found for intent: myIntent (Dialogflow V2) it was suggested that the intent name rather than the action name is used so I check my Actions on Google simulator and the request contains:
"inputs": [
{
"intent": "actions.intent.SIGN_IN",
"rawInputs": [
{
"inputType": "KEYBOARD"
}
],
"arguments": [
{
"name": "SIGN_IN",
"extension": {
"#type": "type.googleapis.com/google.actions.v2.SignInValue",
"status": "OK"
}
}
]
}
],
so I tried updating my Dialogflow intent name to actions.intent.SIGN_IN and modifying the intent name in my Express app accordingly but it doesn't make any difference.
The simulator response includes:
"responseMetadata": {
"status": {
"code": 14,
"message": "Webhook error (206)"
},
but I'm not sure if that is just because for some reason the intent names are not matching up. Any help much appreciated!
As you speculate in the comments, the issue is that your "Get Signin" Intent isn't registered to get the event indicating that the user has signed in (or failed to). Since there is no such Intent setup, it ends up calling the Fallback Intent, which apparently doesn't have an Intent Handler registered in your webhook.
To make your "Get Signin" Intent get the sign-in event, set the "Event" field to actions_intent_SIGN_IN. (Note the similarity to the Intent name you saw in the simulator, but using underscores instead of dots.)
As an aside, the simulator was showing you what the communication between the Assistant and Dialogflow looks like, so it can be somewhat confusing to understand what Dialogflow is doing with it. It didn't have anything to do with the name of your Intent or anything else.
Finally, it often isn't necessary to do this check. You will know if the user is signed in because either the auth token has been set or the id token has been set (depending on your method of Account Linking).
I need to implement the following scenario:
A user signs in with his or her Google credentials.
Thereafter my application checks whether or not this user is using Google
Apps.
If he or she is, my application reads all active users in the same Google
Apps domain (com.google.api.client.googleapis.auth.oauth2.GoogleIdToken.Payload#getHostedDomain).
It is similar to "Find your friends" feature on Facebook. In this case I want to
find all people, who use the same Google Apps domain.
Is it possible to do (both technically and with respect to their terms of use)?
Update 1 (28.08.2017 20:00 MSK):
I've tried to get a list of all users using an access token (gIdToken.payload.accessTokenHash in the code fragment below):
internal open fun createJsonFactory(): JsonFactory = JacksonFactory.getDefaultInstance()
internal open fun createTransport(): HttpTransport = GoogleNetHttpTransport.newTrustedTransport()
internal open fun createVerifier(httpTransport: HttpTransport, jsonFactory: JsonFactory): GoogleIdTokenVerifier {
return GoogleIdTokenVerifier.Builder(httpTransport, jsonFactory)
.setAudience(listOf(clientId))
.build()
}
val idToken = req.queryParams("idtoken")
val httpTransport = createTransport()
val jsonFactory = createJsonFactory()
val verifier = createVerifier(httpTransport, jsonFactory)
val gIdToken = verifier.verify(idToken)
if ((gIdToken != null) && (gIdToken.payload != null)) {
val credential = GoogleCredential().setAccessToken(gIdToken.payload.accessTokenHash)
val directory = Directory.Builder(httpTransport, jsonFactory, credential)
.setApplicationName("Google Auth Test")
.build()
try {
directory.users().list().setCustomer(gIdToken.payload.subject).execute()
}
catch (ex:Throwable) {
ex.printStackTrace()
}
}
When I run directory.users().list().setCustomer(gIdToken.payload.subject).execute(), I get the following error:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized
{
"code" : 401,
"errors" : [ {
"domain" : "global",
"location" : "Authorization",
"locationType" : "header",
"message" : "Invalid Credentials",
"reason" : "authError"
} ],
"message" : "Invalid Credentials"
}
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:146)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:321)
I'm using following Google libraries:
<dependency>
<groupId>google-api-services</groupId>
<artifactId>admin-directory_v1</artifactId>
<version>1.22.0</version>
</dependency>
<dependency>
<groupId>com.google.gdata</groupId>
<artifactId>core</artifactId>
<version>1.47.1</version>
</dependency>
How can I fix the error above?
Update 2 (29.08.2017 11:39 MSK): Tried to use Contacts API
Attempt 1: Contacts API feed
import com.google.gdata.data.extensions.ContactFeed
fun readUsers2(gIdToken:GoogleIdToken, httpTransport: HttpTransport, jsonFactory:JsonFactory) {
val credential = GoogleCredential().setAccessToken(gIdToken.payload.accessTokenHash)
val service = ContactsService("Google Auth Test")
service.setOAuth2Credentials(credential)
val feedUrl = URL("https://www.googleapis.com/auth/contacts.readonly")
val resultFeed: ContactFeed = service.getFeed(feedUrl, ContactFeed::class.java)
}
Result: Exception "Unrecognized content type: text/plain" in
com.google.gdata.client.Service#parseResponseData(com.google.gdata.data.ParseSource, com.google.gdata.wireformats.input.InputProperties, java.lang.Class<E>), see
throw statement below.
private <E> E parseResponseData(ParseSource source, InputProperties inputProperties, Class<E> resultType) throws IOException, ServiceException {
Preconditions.checkNotNull("resultType", resultType);
AltFormat inputFormat = null;
String alt = inputProperties.getQueryParameter("alt");
if (alt != null) {
inputFormat = this.altRegistry.lookupName(alt);
}
if (inputFormat == null) {
inputFormat = this.altRegistry.lookupType(inputProperties.getContentType());
if (inputFormat == null) {
throw new ParseException("Unrecognized content type:" + inputProperties.getContentType());
}
}
Attempt 2: Contacts API query
fun readUsers3(gIdToken:GoogleIdToken, httpTransport: HttpTransport, jsonFactory:JsonFactory) {
val credential = GoogleCredential().setAccessToken(gIdToken.payload.accessTokenHash)
val service = ContactsService("Google Auth Test")
service.setOAuth2Credentials(credential)
val feedUrl = URL("https://www.googleapis.com/auth/contacts.readonly")
val query = Query(feedUrl)
val resultFeed = service.query(query, ContactFeed::class.java)
}
Result: Same exception as in attempt 2.
Update 3 (29.08.2017 13:04 MSK):
I tried to get a list of users using the API Explorer.
I got the 403 error. Details are given below.
Request:
GET https://www.googleapis.com/admin/directory/v1/users?domain={MYDOMAIN}&fields=users(emails%2Cid%2Cname)&key={YOUR_API_KEY}
Response:
403
- Show headers -
{
"error": {
"errors": [
{
"domain": "global",
"reason": "forbidden",
"message": "Not Authorized to access this resource/api"
}
],
"code": 403,
"message": "Not Authorized to access this resource/api"
}
}
Update 4 (30.08.2017 13:19 MSK):
Finally, I managed to get rid of authentication and authorization errors (in a
test installation of a G suite app).
However, now the following calls return an empty list of users (without errors).
val directory = Directory.Builder(
NetHttpTransport(),
JacksonFactory.getDefaultInstance(),
credential)
.setApplicationName("Google Auth Test")
.build()
val users = directory.users().list()
You need to get sufficient permissions from the user to fetch the list of all users in the domain. Moreover, it will only work if logged in user is super admin of the domain.
You can get list of permissions here.
This question is related to Google API/get directory contacts
I'm posting an answer here since this one is more google friendly:
The Admin Directory Users:list resource allows company directory listing even without admin privileges.
Just make sure you set the viewType to domain_public and you're good to go:
https://www.googleapis.com/admin/directory/v1/users?customer=my_customer&viewType=domain_public
A scope of https://www.googleapis.com/auth/admin.directory.user.readonly should be enough.
Check this documentation to retrieve all users in the same domain, use the following GET request and include the authorization described in Authorize requests. For readability, this example uses line returns:
GET https://www.googleapis.com/admin/directory/v1/users
?domain=primary domain name&pageToken=token for next results page
&maxResults=max number of results per page
&orderBy=email, givenName, or familyName
&sortOrder=ascending or descending
&query=email, givenName, or familyName:the query's value*
For the request and response properties, you may want to use the Users: list method wherein it retrieves a paginated list of either deleted users or all users in a domain. This request requires authorization with at least one of the following scopes (read more about authentication and authorization).
https://www.googleapis.com/auth/admin.directory.user.readonly
https://www.googleapis.com/auth/admin.directory.user
We are trying to use UCWA 2.0 API for integrating Skype for Business Online. Using MS developer account(Azure AD tenant) with free trial.
After home pool server discovery when we create the application resource we get limited resources links in the response of POST
UCWA 2.0 API documentation mentions many resources and links for all of them are not provided in the response of above POST.
Quesiton -1 : Are all UCWA 2.0 REST resources available for use with Skype for Busines Online? If not then which are not exposed and when they will be available?
Question 2:
We are struggling specially with conversationlogtranscript. Objective is to get the chat transcript of chat conversation in a meeting .
What we have tried is here:
Hit to POST https://webpoolmaain102.infra.lync.com/ucwa/oauth/v1/applications/10241512914/communication/makeMeAvailable ( to add modalities like messaging)
with body
{
"audioPreference" : "PhoneAudio",
"phoneNumber" : "4255552222",
"signInAs" : "BeRightBack",
"supportedMessageFormats" : [
"Plain",
"Html"
],
"supportedModalities" : [
"PhoneAudio",
"Messaging"
]
}
returns 204 No Content
Hit to PUT https ://webpoolmaain102.infra.lync.com/ucwa/oauth/v1/applications/10241512914/communication, (where we are trying to enable a specific parameter "conversationHistory")
returns :
428 Precondition Required with If-Match header as 3fc81bb8-98f5-48b3-8981-d2fbd05305f. or 1529525322 (communications etag value)
Response body in both base : {
"code": "PreconditionRequired",
"message": "Your request couldn't be completed."
}
here body of this PUT as below:
{
"simultaneousRingNumberMatch" : "Disabled",
"videoBasedScreenSharing" : "Disabled",
"rel" : "communication",
"audioPreference" : "PhoneAudio",
"conversationHistory" : "Enabled",
"lisLocation" : "samplevalue",
"lisQueryResult" : "Succeeded",
"phoneNumber" : "tel : +14255524222",
"publishEndpointLocation" : true,
"supportedMessageFormats" : [
"Plain",
"Html"
],
"supportedModalities" : [
"PhoneAudio",
"Messaging"
]
}
Header of this PUT is as below:
If-Match:3fc81bb8-98f5-48b3-8981-d2fbd05305f
Authorization:Bearer
Accept:application/json
Content-Type:application/json
Host:webpoolmaain102.infra.lync.com
Here we have tried "If-Match" header with both : (1) "3fc81bb8-98f5-48b3-8981-d2fbd05305fc": (this value comes with text "please pass this in a PUT request") and (2) "etag": "1529525322" . Both from "communication" section inside embedded of the application resources.
So both ways to enable conversationHistory settings through communication resources is giving 428 issue which shoudl not come as we are passing "If-Match" header already.
Can you pls suggest if we are doing something wrong here and how can we get "conversationLogTranscript" of a user's meetings
Regards,
Sourabh
I am using "Google Application Default Credentials" in my scala application to talk to the google sheets api. However, I am getting a "PERMISSION_DENIED" error message from the api response.
Here is a snippet of my code:
private val client: Sheets = {
val serviceAccountScopes = List(SheetsScopes.SPREADSHEETS_READONLY)
// https://developers.google.com/identity/protocols/application-default-credentials
val credential: GoogleCredential = GoogleCredential
.getApplicationDefault()
.createScoped(serviceAccountScopes.asJava)
new Sheets.Builder(httpTransport, jsonFactory, credential)
.setApplicationName(applicationName)
.build()
}
val response = client.spreadsheets().values().get(spreadSheetId, "Total Cost!A2:C2").execute()
val values = response.getValues
Here is the error message:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 403
Forbidden { "code" : 403, "errors" : [ {
"domain" : "global",
"message" : "Request had insufficient authentication scopes.",
"reason" : "forbidden" } ], "message" : "Request had insufficient authentication scopes.", "status" : "PERMISSION_DENIED"
}
I did enabled google sheet api in the google developer console, and the sheet I am trying to read is under my google drive.
The only thing I am not sure about is the google sheet api doc https://developers.google.com/sheets/guides/authorizing#OAuth2Authorizing does not mention anything about if the api supports "Google Application Default Credentials" or not.
Anything I might miss or did wrong here?