I'm looking for a basic example on how to utilize DialogFlow's batchUpdate, and how to utilize batchUpdateResponse to show an actual response once complete.
Have found no examples for DialogFlow V1 or V2 (at this point either would be helpful), the below is all I've managed to setup - looking for the missing arguments to be added:
$intentsClient->batchUpdateIntents($formattedParent, $languageCode, $test_3);
Currently using PHP https://github.com/googleapis/google-cloud-php/tree/83ae284c025f6e93b9ce835b987932c425b5a9de/Dialogflow but any language is fine here.
Ended up figuring this out through the use of https://developers.google.com/apis-explorer/ and the Google Client Library for PHP (https://github.com/googleapis/google-api-php-client).
Below is a basic example for updating the text on two intents at once, via PHP. Hopefully this helps someone in the future, am somewhat surprised at the general lack of helpful documentation and/or examples for using DialogFlow's API V2 (or even V1 for that matter). So many awesome things can be done by using this rather than their Dashboard to train your bot!
// Global variable pointing to the .json file downloaded with private key from DialogFlow
putenv('GOOGLE_APPLICATION_CREDENTIALS=directory-of-file/google-service-acount-key.json');
// Setup Google Client
require __DIR__.'/vendor/autoload.php';
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope('https://www.googleapis.com/auth/cloud-platform');
$httpClient = $client->authorize();
// Setup array to update intent (minified)
$update_intent = array('intentBatchInline'=>array('intents'=>array(
0=>array('name'=>'projects/YOUR-PROJECT-NAME/agent/intents/FIRST-INTENT-ID','displayName'=>'FIRST-INTENT-NAME','messages'=>array(0=>array('text'=>array('text'=>array(0=>'FIRST-INTENT-TEXT-TO-UPDATE',),),),),),
1=>array('name'=>'projects/YOUR-PROJECT-NAME/agent/intents/SECOND-INTENT-ID','displayName'=>'SECOND-INTENT-NAME','messages'=>array(0=>array('text'=>array('text'=>array(0=>'SECOND-INTENT-TEXT-TO-UPDATE',),),),),),),),
);
// Post to DialogFlow API
$response = $httpClient->post('https://dialogflow.googleapis.com/v2/projects/PROJECT-NAME-HERE/agent/intents:batchUpdate', [
GuzzleHttp\RequestOptions::JSON => $test_batch_intent_1
]);
// Print out response for troubleshooting
print_r($response->getBody()->getContents());
echo "<br /><br />Here's to getting past DialogFlow API's hurdles! :)";
exit;
This is similar to my answer. Where I have given a complete example. Do check it out.
Stack Overflow answer.
And this is based out of NodeJs. As you told the language does not matter.
And do check out this documentation for different kinds of examples. This document covers even the batchUpdate functionality.
Please check these out:
GitHub repo
GitHub repo
Related
I am no professional Android developer and I'm having problems to get the Google PlayIntegrity token from my app to decode via PHP through my back-end server and couldn't find much help online.
I included the Google PHP API onto my server, integrated the API into my app and activated&linked it on the Play Console. But it seems I am doing something wrong, I am getting the following PHP error messages:
Warning: Attempt to read property "appLicensingVerdict" on null
My code:
<?php
namespace foo;
use Google\Client;
use Google\Service\PlayIntegrity;
use Google\Service\PlayIntegrity\DecodeIntegrityTokenRequest;
require_once __DIR__ . '/google/vendor/autoload.php';
// Google Integrity token, as obtained from Google through my app:
$token = $_POST['IntegrityToken'];
$client = new Client();
$client->setAuthConfig('google/credentials.json');
$client->addScope(PlayIntegrity::PLAYINTEGRITY);
$service = new PlayIntegrity($client);
$tokenRequest = new DecodeIntegrityTokenRequest();
$tokenRequest->setIntegrityToken($token);
$result = $service->v1->decodeIntegrityToken('com.myapp.game', $tokenRequest);
// Read and handle the JSON response:
$appLicensingVerdict = $result->accountDetails->appLicensingVerdict;
// ... more fields are available in the JSON... see Google documentation
// Check/verify the obtained response values.....
?>
Any help would be much appreciated! Many thanks!
Also thanks to hakre's help, I was able to solve the problems I was facing. The code works fine with tokenPayLoadExternal included:
$appLicensingVerdict = $result->tokenPayloadExternal # <-- this
->accountDetails
->appLicensingVerdict
;
We got an email regarding updating discovery document.
Starting November 1, 2021, projects which have not updated their discovery document will no longer be supported and will stop working.
We are using external API library: googleapis/google-api-php-client, for Webmasters API.
Currently I'm using the below API call.
$client = new Google_Client();
$client->setApplicationName(xxxxxxxxxxxxxxxx);
$client->setAuthConfig(xxxxxxxxxxxxxxxxxxxxxx);
$scopesArray = array(
'https://www.googleapis.com/auth/webmasters'
);
$client->setScopes($scopesArray);
...................................................
.....................................................
$googlewebmasterssearchsnalyticsobject = new \Google_Service_Webmasters_SearchAnalyticsQueryRequest();
$googlewebmasterssearchsnalyticsobject->setStartDate('1970-01-01');
$endDate = gmdate('Y-m-d');
$googlewebmasterssearchsnalyticsobject->setEndDate($endDate);
$googlewebmasterssearchsnalyticsobject->setDimensions(['page', 'date']);
$googlewebmasterssearchsnalyticsobject->setSearchType('web');
..................................................................
What should I update in the above API call?
You aren't directly using the discovery document the Client library does for you. Any issues should have been addressed in that library already.
If you are worried you should cross post this issue over on their issue forum. if there is an issue its something that should be fixed in the library
I can see this question was cross posed to Update the Google Search Console API discovery document #2149
If you're using Google's client library, you must update the discovery doc
From: https://www.googleapis.com/discovery/v1/apis/webmasters/v3/rest
To: https://searchconsole.googleapis.com/$discovery/rest
In my case, I was using Google's JavaScript client library, and was not providing the discoveryDocs parameter. I needed to replace instances of webmaster / v3 to searchconsole / v1, as shown below.
From:
gapi.client.load('webmasters', 'v3').then(function(){
To:
gapi.client.load('searchconsole', 'v1').then(function(){
I've been exploring the various Document APIs and have settled on Google Docs API v1 to try to accomplish what I want.
What I want to accomplish:
Create A Doc
Dump some text into it
Place the doc into a G Suite Drive Folder
What I've got
All the respective relevant APIs enabled + Service Account Credentials (have used this with other Google Services just fine)
All of the Google API PHP stuff installed via composer
What I think is a method to correctly authenticate into the "Documents" REST API (please see below)
public function initializeDocs() {
// Create and configure a new client object.
$client = new Google_Client();
$client->setApplicationName($appName);
$client->setAuthConfig("$KEY_FILE_LOCATION");
$client->setScopes(['https://www.googleapis.com/auth/documents']);
$document = new Google_Service_Docs_Document($client);
$document->setTitle($title);
return $document; // Just seeing what get outputs
/*
...Getting Stuck here below is the code from Google's "Creating and managing documents" documentation
$document = new Google_Service_Docs_Document(array(
'title' => $title
));
$document = $service->documents->create($document);
printf("Created document with title: %s\n", $document->title);
After this....(can/will address in separate post, if possible)
1) Add content
2) Set document creator?
3) "Upload" / move to Drive folder location
*/
}
My issues:
I'm having a hard time finding/undersanding 'create' methods; Google's Creating and managing documents references the 'Documents Collection'
At least in the PHP library, I'm not seeing where I would find that (I searched the ~/vendor/google/apiclient-services/src/Google/Service/Docs directory and didn't see any 'create' method);
Could someone please point me in the right direction? Many thanks in advance!
I've been taking a look at the Google API PHP Client and would like to use it to add rows to a Google Sheet. From the code, it looks like one would use this method:
public function insert($fileId, Google_Service_Drive_Property $postBody, $optParams = array())
{
$params = array('fileId' => $fileId, 'postBody' => $postBody);
$params = array_merge($params, $optParams);
return $this->call('insert', array($params), "Google_Service_Drive_Property");
}
but I can't really tell what the parameters would be. Am I heading in the right direction? Also, not quite sure on how to connect to a specific Sheet. Please advise.
Thanks!
Use Google sheets class from zend framework 1.12. They have very nicely coded library for Google Spreadsheets
https://github.com/zendframework/zf1/tree/master/library/Zend/Gdata/Spreadsheets
I figured out how to work this and wanted to share with you guys. As I stated in a comment, I did not think using Zend's GData class was a good way for me since it's very dependent on other classes throughout the framework, thus being too heavy.
So I ended up using this Spreadsheet Client on top of Google's API. Google's API is used to authenticate my service, then I start calling the Spreadsheet Client library afterwards.
After spending over a day of Googling for various problems I had for the authentication process, here's what I did to make things work:
Created a new project for Google API here
Clicked "APIs" menu on the left side under "APIs & Auth"
Searched the Drive API and enabled it (can't remember if it was necessary)
Clicked the "Credentials" menu on the left
Clicked "Create new Client ID" button under OAuth
Selected "Service Account"
After info showed & json downloaded (not needed), I clicked "Generate new P12 Key" button
I saved the p12 file somewhere I could access it through PHP
Then in the code, I added the following lines:
$email = 'somethingsomethingblahblah#developer.gserviceaccount.com';
$CLIENT_ID = $email;
$SERVICE_ACCOUNT_NAME = $email;
$KEY_FILE = 'path/to/p12/file';
$SPREADSHEETS_SCOPE = 'https://spreadsheets.google.com/feeds';
$key = file_get_contents($KEY_FILE);
$auth = new Google_Auth_AssertionCredentials(
$SERVICE_ACCOUNT_NAME,
array($SPREADSHEETS_SCOPE),
$key
);
$client = new Google_Client();
$client->setScopes(array($SPREADSHEETS_SCOPE));
$client->setAssertionCredentials($auth);
$client->getAuth()->refreshTokenWithAssertion();
$client->setClientId($CLIENT_ID);
$accessToken = $client->getAccessToken();
Also, I had to make sure I:
Shared my spreadsheet specifically with the email address on my service account in the code above
Synced my server's time (I'm running Vagrant CentOS so it's slightly different)
I believe you can run this code with other services beyond Spreadsheets, such as Youtube, Analytics, etc., but you will need to get the correct scope link (see $SPREADSHEETS_SCOPE above). Remember, this is only when using the Service Account on the Google Console, which means you are programmatically getting data from your code. If you are looking to have others users sign in using the API, then it's different.
As in the subject, I'm working with the Google DFA (DoubleClick for Advertisers) APIs v1.20 and I'm trying to get the list of all my Advertisers.
I didn't found any client library for PHP and DFA APIs v1.20.
The connection is established by SOAP, as requested by Google API docs (https://developers.google.com/doubleclick-advertisers/docs/getting_started)
The authentication process seems to work correctly but the list request return the following error:
WSDoAllReceiver: security processing failed; nested exception is: org.apache.ws.security.WSSecurityException: General security error (WSSecurityEngine: Callback supplied no password for: MyUsername)
To build the header I'm using the following code
$advertiserService = new SoapClient($advertiserWsdl, $options);
// Set headers.
$headers = array(DfaHeadersUtil::createWsseHeader($username, $authToken),
DfaHeadersUtil::createRequestHeader($namespace, $applicationName));
Where the DfaHeadersUtil is a class into the file DfaHeadersUtil.php provided by Google as "header creator".
Is there anybody could help me with this?
Thank you in advance,
Mauro
SOLVED:
The problem was given by not sufficient permissions assigned by the admin to my user..
Easy solution that made me waste half week.. :(
What I learnt:
Occam's razor: "the simplest explanation is usually the correct one"..
Next time.. check the permissions :)
Thank you