I am trying to run the following code with the new Google Business Profile API:
$mybusinessbusinessinformationService = new Google\Service\MyBusinessBusinessInformation($client);
try
{
$locations = $mybusinessbusinessinformationService->accounts_locations->call('list',['parent'=>'accounts/1111111111111111111']);
var_dump($locations);
} catch(Exception $e){
var_dump(print_r($e->getMessage(),1));
}
But I am getting the following error:
(list) missing required param: 'parent'
As far as I can tell it seems that I am parsing the param properly.
For people that are searching for an answer:
Since Google updated its API, it's a requirement to parse readMask as well:
$mybusinessbusinessinformationService = new Google\Service\MyBusinessBusinessInformation($client);
$params = array('readMask'=> "title,name");
$locations = $mybusinessbusinessinformationService->accounts_locations->listAccountsLocations($getAccountName,$params);
var_dump($locations);
You can find the mask parameters here:
https://developers.google.com/my-business/reference/businessinformation/rest/v1/locations
Related
I have been searching around for examples but the documentation on:
http://php.net/manual/en/solrclient.query.php
and
https://www.ayalon.ch/en/code-samples/solr-php-client-example
does not give me enough information to alter for my setup.
I am trying to execute a solr query using php from my website.
The search box form method is post and the input name is q.
This is all of the php I have at the moment; I was testing the connection.
<?php
require_once('C:\Program Files\Solr\solr-7.5.0\dist\solr-php-client-master\Apache\Solr\Service.php');
$client = new Apache_Solr_Service( 'localhost', '8983', '/solr/#/sqltest' );
if ( ! $client->ping() ) {
echo 'Solr service not up dude.';
}
else{
echo 'ayee we have a connection here!';
}
//to view the specifics of this setup use
//var_dump($client);
?>
Being new to php, Im really trying to find the proper way to perform the search and display the default json response.
I already have documents indexed to search so my code does not need to add any docs as seen in some of the above tutorials.
When I use this code:
$query = new SolrQuery();
$query->setQuery('lucene');
$query->setStart(0);
$query->setRows(10);
$query->addField('id')->addField('date')->addField('Problem')->addField('Solution');
$query_response = $client->query($query);
$response = $query_response->getResponse();
print_r($response);
I get an error because the class SolrQuery is not found.
I'm using the twitter api to get my latest mentions.
Twitter api link: https://dev.twitter.com/rest/reference/get/statuses/mentions_timeline
Function used to get last mentions:
function twitter_get_tweets(){
$connection = $this->twitter_auth();
$latest_tweet = $connection->get('statuses/mentions_timeline', array('count' => 1));
return $latest_tweet;
}
Preview of response: http://projects.helpful.ninja/twitter/
Sadly im not able to access the variables in there directly, such as the text node.
Example:
[text] => #pr0b_ Submit a request to our Support team and they'll be in touch ASAP
Been testing something like:
$twitter_bot = new twitter_bot_functions($twitter_settings['api_key'], $twitter_settings['api_secret'], $twitter_settings['access_token'], $twitter_settings['access_token_secret']);
$get_latest_mention = $twitter_bot->twitter_get_tweets();
echo $get_latest_mention['text'];
Does someone have a idea what I'm doing wrong?
It is an array first and then a stdClass object. So you should use it like
echo $get_latest_mention[0]->text;
I'm trying to access my Google Analytics data using a service account. I've created one in the Developers Console and I've enabled the Google Analytics API in that same console, but somehow, I can't manage to pull data from the API.
I've used the script on this page.
My code is as follows:
<?php
$keyfile = 'google/key.p12';
// Initialise the Google Client object
$client = new Google_Client();
$client->setApplicationName('MyNAME');
$client->setAssertionCredentials(
new Google_AssertionCredentials(
'XXXX#developer.gserviceaccount.com', array('https://www.googleapis.com/auth/analytics.readonly'), file_get_contents($keyfile)
)
);
$client->setClientId('XXXX.apps.googleusercontent.com');
$client->setAccessType('offline_access');
$analytics = new Google_AnalyticsService($client);
$analytics_id = 'ga:UA-XXXXXX-1'; // http://productforums.google.com/forum/#!topic/analytics/dRuAr1K4waI
// get data for the last 2 weeks
$lastWeek = date('Y-m-d', strtotime('-2 week'));
$today = date('Y-m-d');
// Test connection
try {
$results = $analytics->data_ga->get($analytics_id, $lastWeek, $today, 'ga:visits');
echo '<b>Number of visits this week:</b> ';
echo $results['totalsForAllResults']['ga:visits'];
} catch (Exception $e) {
echo 'There was an error : - ' . $e->getMessage();
}
?>
Note: if it says "XXXX", that means I've removed part of the string for security purposes; the proper strings are in my actual script.
It should either display the number of users or a error, but I just get a blank screen. I'm sure the URL to the keyfile is correct.
Does anybody have suggestions on how to fix this? That would be much appreciated.
It looks like you are using your property Id (UA-XXXXX-1) in place of your view (profile) id. If you go to Google Analytics Query Explorer it makes it easy to see what your actual ga:XXXX view (profile) id is. Any given property can have multiple view's (profiles). This reference guide gives a good description of the parameters that this request requires.
I am trying to remove a number from my Twilio account using the following code:
// remove the number from Twilio
$client = new Services_Twilio(TWILIO_SID, TWILIO_TOKEN);
try {
// Remove the number
$purchaseNumber = $client->account->incoming_phone_numbers->delete(array(
"PhoneNumber" => "+447903000000"
));
} catch (Exception $e) {
echo 'Error = '.$e->getMessage();
}
Which throws the following exception:
Error = The requested resource /2010-04-01/Accounts/jhsdkfjhdsjhf32370685sjhgfjhdsjfgsdjh/IncomingPhoneNumbers/Array.json was not found
I assume that the format of the request to delete the number is wrong but there doesn't seem to be any examples in the documentation on how to do it - can anyone shed any light on where I am going wrong?
So it seems that you cannot delete a number using the number - you have to use the SID which is returned when you purchase the number. Details here:
http://web.onassar.com/blog/2012/06/16/twilio-incoming-phone-numbers-releasing-deletion/
I'm doing what I would consider to be the most basic API call to the web-app at http://rolz.org/api/?4d20 using Pest PHP REST client. Using a Chrome plugin REST client, I get the expected results without an error:
result=45
details= [ 16 +20 +3 +6 ]
code=4d20
illustration=<span class="dc_dice_a">4</span><span class="dc_dice_d">D20</span>
timestamp=1370200094
However, using Pest PHP REST client, my results are prepended with an error message:
string $rolldice = result=Error: please check your formula (/52)
details=/ [ 9 +16 +20 +7 ]
code=/4d20
illustration=<span class="dc_operator">/</span><span class="dc_dice_a">4</span><span class="dc_dice_d">D20</span>
timestamp=1370200381
using this code:
include '../Pest.php';
function callDieRoller($num, $faces){
$result = array();
$curl = curl_init();
$url = 'http://rolz.org/api/?';
$pest = new Pest($url);
$rolldice = $pest->get($num.'d'.$faces);
$results = $rolldice;
return $results;
}
Why am I getting errors when making the API call with Pest?
It's because Pest ensures / between base api url and called url, so you are calling something like http://rolz.org/api/?/4d20. To make it work properly, you must define base url without question mark, and add it in front of every call:
$url = 'http://rolz.org/api/';
$pest = new Pest($url);
$rolldice = $pest->get('?'.$num.'d'.$faces);
$results = $rolldice;