I'm trying to list all the merchants in our CSS center throughout the content API. The documentation states that you need to include the parameter view=css when you want to list all the merchants in your CSS account (content API V2.1), instead of listing the accounts in an MCA.
When I try to do this through the content API (PHP client), I get the error message:
(list) unknown parameter: 'view'
The code we use to get the merchants is:
$client = new Google_Client();
// client instantiation logic not included here
$service = new Google_Service_ShoppingContent($client);
// $mca_id = our CSS ID
$merchants = $service->accounts->listAccounts($mca_id, array("maxResults" => 100, "view" => "css"));
I can't seem to find how I need to include the parameter view through the content API in PHP. The documentation also states that the View should be an ENUM, but I'm not quite sure how to use this.
Documentation link to the accounts.list
The Content API PHP client doesn't seem to have the parameter view=css added in the accounts.list function.
To get this working you have to do a manual HTTP call throughout the client:
$client = new Google_Client();
// client instantiation logic not included here
// returns a Guzzle HTTP Client
$httpClient = $client->authorize();
// $mca_id = our CSS ID
$merchants = json_decode($httpClient->get('https://www.googleapis.com/content/v2.1/' . $mca_id . '/accounts?maxResults=100&view=CSS')->getBody()->getContents());
Related
I am new to the Infusion API and I have a couple of questions that I am unable to find a specific answer to.
I have used the PHP SDK and installed via composer
1) Within the new API is there away that I can view all tags that have been created?
2) I have created and got my client clientId and clientSecret via but I am unsure how I connect it to the app name that I want to fetch the tags for.
I have given it an attempt by looking at code examples I have seen via Google however I am getting the following error - Call to undefined method Infusionsoft\Infusionsoft::dsQuery()
Code:
<?php
//Connect to the Infusionsoft API
require_once 'vendor/autoload.php';
$infusionsoft = new \Infusionsoft\Infusionsoft(array(
'clientId' => 'key',
'clientSecret' => 'key',
));
// Fetch the required tags for this place
$getFields = array('Id','GroupDescription', 'GroupName');
$query = array('GroupName' => '%');
$tags = $infusionsoft->dsQuery("ContactGroup",1000,0,$query,$getFields);
var_dump($tags);
?>
First of all, there's no new API. Improvements are added to Infusionsoft API all the time, but it's still the same updated API. If you mean new Infusionsoft PHP SDK, then example request to get the tags looks this way:
$infusionsoft->data()->query('ContactGroup', $limit, $page, $queryData, $selectedFields, $orderBy, $ascending);
query() method is implemented in Infusionsoft/Api/DataService.php file
You connect to a specific Infusionsoft account during oAuth authorization flow. This basic flow is shown, for example, in PHP SDK examples
The error you see means exactly what it says - there's no such method dsQuery() in the updated SDK. The link to the SDK code where you can see all available methods was provided in the first point.
How can I access the full referral path for one session/user through Google Reporting API V4 ? In this case in PHP.
For example we have following code found on Google's Reporting API V4 Documentation.
(https://developers.google.com/analytics/devguides/reporting/core/v4/quickstart/service-php)
function getReport(&$analytics) {
// Replace with your view ID, for example XXXX.
$VIEW_ID = "<REPLACE_WITH_VIEW_ID>";
// Create the DateRange object.
$dateRange = new Google_Service_AnalyticsReporting_DateRange();
$dateRange->setStartDate("7daysAgo");
$dateRange->setEndDate("today");
// Create the Metrics object.
$sessions = new Google_Service_AnalyticsReporting_Metric();
$sessions->setExpression("ga:sessions");
$sessions->setAlias("sessions");
// Create the ReportRequest object.
$request = new Google_Service_AnalyticsReporting_ReportRequest();
$request->setViewId($VIEW_ID);
$request->setDateRanges($dateRange);
$request->setMetrics(array($sessions));
$body = new Google_Service_AnalyticsReporting_GetReportsRequest();
$body->setReportRequests( array( $request) );
return $analytics->reports->batchGet( $body );
}
This part is interesting:
$sessions->setExpression("ga:sessions");
$sessions->setAlias("sessions");
Dimensions & Metrics Explorer
(https://developers.google.com/analytics/devguides/reporting/core/dimsmets)
The path of the referring URL (e.g., document.referrer). If someone
places on their webpage a link to the property, this is the path of
the page containing the referring link.
The full referring URL including the hostname and path.
I am assuming that I have to go this way just fetching the desired dimensions/metrics:
$sessions->setExpression("ga:referralPath");
$sessions->setAlias("referral_path");
or
$sessions->setExpression("ga:fullReferrer");
$sessions->setAlias("full_referrer");
Would be this the right approach?
If not is there another way to accomplish this?
And another question:
When making a request with this metrics/dimensions:
$sessions->setExpression("ga:referralPath");
$sessions->setAlias("referral_path");
How Google knows from which session to take the referralPath?
Try to read through Traffic Sources - Dimensions and Metrics, this reference document lists and describes all the dimensions and metrics available through the Real Time Reporting API.
Here's a sample of dimension: rt:referralPath - The path of the referring URL (e.g. document.referrer). If someone places a link to your property on their website, this element contains the path of the page that contains the referring link. This value is only set when rt:medium=referral.
Note: Use Google Analytics superProxy to handle many of the implementation details of working with Google Analytics APIs on authentication, caching, and transforming API responses to formats used directly with visualization and chart libraries.
You may also try to read Management API, this API is a guides that will help you initially get an application up and running and then the documentation will dive into the various topics which should help you interact with the API to perform such things as account, user, and data management. There is also a complete set of reference documents, which give details of every parameter of each API endpoint and include API sample code.
Background: We've got two Accounts that each hold several profiles.
I am developing an application in PHP using the provided API.
I can successfully retrieve data from both accounts separately, but whenever I instantiate the Google_Client object a second time (using a different variable name, of course), it instantly logs me out of the first account and overwrites the first account's settings.
Has anyone successfully managed to log into two accounts at the same time using the PHP API Client and could give me a hint on how to accomplish that?
Relevant code sections:
$client1 = new Google_Client();
$client1 ->setAssertionCredentials($omitted);
$client1 ->setClientId($id);
$client1 ->setAccessType('offline_access');
$gaClient1 = new Google_AnalyticsService($client);
//I can now successfully query the Analytics API, but when I do this
$client2 = new Google_Client();
//and query gaClient1 again, it throws a "you must login/401"-error
I guess the problem is that the api uses caching with files to handle request. Now when the second client is created, it is using the same cache folder and thus it is overwriting the previous settings.
now in your config.php is the following:
'ioFileCache_directory' =>
(function_exists('sys_get_temp_dir') ?
sys_get_temp_dir() . '/Google_Client' :
'/tmp/Google_Client')
This is the part that is always returning the same result. When creating a client, you can send in your own config array and it will be combined with the master. So you could use:
$client1 = new Google_Client(array('ioFileCache_directory' => '/tmp/dirclient1'));
$client2 = new Google_Client(array('ioFileCache_directory' => '/tmp/dirclient2'));
Also in your code you created a $client1, but later on you use $gaClient1 = new Google_AnalyticsService($client);. Shouldnt that be $gaClient1 = new Google_AnalyticsService($client1);?
I am trying to upload a video to youtube using client library v3.
The v3 library is experimental and does not have much documentation
(samples provided does not include youtube)
I have properly authenticated user with oauth 2.0. And when I have access token, I am trying with this code.
if ($client->getAccessToken()) {
$snippet = new Google_VideoSnippet();
$snippet -> setTitle = "Demo title";
$snippet -> setDescriptio = "Demo descrition";
$snippet -> setTags = array("tag1","tag2");
$snippet -> setMimeType = 'video/quicktime';
$video = new Google_Video();
$video -> setSnippet($snippet);
// Not sure what to do now....
$_SESSION['access_token'] = $client->getAccessToken();
}
From the docs,
I need to supply a part parameter
The part parameter serves two purposes in this operation. It identifies the properties that the write operation will set as well as the properties that the API response will include.
The part names that you can include in the parameter value are snippet, contentDetails, player, statistics, status, and topicDetails. However, not all of those parts contain properties that can be set when setting or updating a video's metadata. For example, the statistics object encapsulates statistics that YouTube calculates for a video and does not contain values that you can set or modify. If the parameter value specifies a part that does not contain mutable values, that part will still be included in the API response.
But it lacks documentation except a python example which I am not able to understand.
(the example is at the bottom of the link , I provided)
Please, dont give example/links to zend library, it uses auth-sub which I dont want.
I want to use oauth 2.0.
The code to upload a video looks like this.
$youtubeService->videos->insert($part, Google_Video $postBody, $optParams = array());
'part' is what you want the request to return. In this case that could just be status, which return information about the status of the upload.
The release of the Google PHP client library might be old, so you'll want to checkout the source at https://code.google.com/p/google-api-php-client/
I am trying to render a SoundCloud HTML5 widget using the PHP API, but every time I run the command I think should return the HTML for the widget, I simply get an Exception:
The requested URL responded with HTTP code 302
I realise this is a redirect. What I don't know is why that's all I ever get, or what to do about it to actually get the widget HTML.
The documentation on the API says that to embed the widget using PHP you should do this:
<?php
require_once 'Services/Soundcloud.php';
// create a client object with your app credentials
$client = new Services_Soundcloud('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET');
// get a tracks oembed data
$track_url = 'http://soundcloud.com/forss/flickermood';
$embed_info = $client->get('/oembed', array('url' => $track_url));
// render the html for the player widget
print $embed_info['html'];
I'm running this:
// NB: Fully authorised SoundCloud API instance all working prior to this line
// $this->api refers to an authorised instance of Services_Soundcloud
try {
$widget = array_pop(
json_decode( $this->api->get('oembed', array('url' => $track_url)) )
);
print_r($widget);
} catch (Exception $e)
{
print_r($e->getMessage());
}
where "track_url" is actually the URL I get back when asking SoundCloud for a track object earlier in the app using the same API.
I'm not actually sure this URL is correct in the first place, because the track object I get back gives the 'uri' in the form:
[uri] => https://api.soundcloud.com/tracks/62556508
The documentation examples all have a straight http://soundcloud.com/username/track-permalink URL - but even using a known path to a public track the attempt to run the API oembed method fails... I still get a 302 Exception.
Finally, there are mentions of setting "allow_redirects" to false in the 'get' command, but this has no effect when I add to the parameters used to build the query to the API. I also tried adding additional cURL options, but that too had no effect.
I have definitely enabled API access to the track within SoundCloud.
Kind of banging my head off the wall on this. If anyone has any pointers I'd be very grateful to hear them. Just for clarity's sake, I am able to access all the user data, comments etc. via the API instance I have created, so it appears to be working fine.
Thanks for pointing this out. There was a bug in the documentation that lead you astray. Sorry about that. I've updated the docs to fix the bug. Here's the updated code sample:
<?php
require_once 'Services/Soundcloud.php';
// create a client object with your app credentials
$client = new Services_Soundcloud('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET');
$client->setCurlOptions(array(CURLOPT_FOLLOWLOCATION => 1));
// get a tracks oembed data
$track_url = 'http://soundcloud.com/forss/flickermood';
$embed_info = json_decode($client->get('oembed', array('url' => $track_url)));
// render the html for the player widget
print $embed_info->html;
Note the differences:
You need to set CURLOPT_FOLLOWLOCATION to 1 as mentioned in the comments above.
You need to wrap the return from $client->get in json_decode
The result is an stdClass object, not an Array and so the html property has to be accessed using the -> operator.
Hope that helps. Feel free to comment in case you're still having problems and I'll amend my answer.