This is the sample code that I am using to get my contacts from Google People API. Works fine.
$people_service = new Google_Service_PeopleService($client); // TODO: Use service object to request People data
$connections = $people_service->people_connections->listPeopleConnections ('people/me',
array('personFields' => 'names,emailAddresses,biographies',
'pageSize' => 25,
'sortOrder' => 'FIRST_NAME_ASCENDING',
));
But I couldn't figure out how to list and manage Contact Groups (like friends, family etc.).
This is the code I am trying without success.
$groups_list = $people_service->contactGroups->listcontactGroups();
Sources I could find:
https://developers.google.com/resources/api-libraries/documentation/people/v1/php/latest/class-Google_Service_PeopleService.html
https://developers.google.com/people/api/rest/v1/contactGroups/list
Have you check if you need to call an extra function as indicated in this documentation? Follow the PHP sample for printing the names for up to 10 connections.
$groups_list = $people_service->contactGroups->listcontactGroups();
$group_list->getContactGroups( );
Related
I am trying to get the number of downloads of an application that I have uploaded to Google Play.
I am searching for an API (or something similar) that retrieves to me the number of downloads with the authentification of the user. I do not want third party applications (like AppAnnie).
It would be great if it could be on PHP and I found that there is a library which I think it is the most closest API I could find to get data from Google applications.
Google APIs Client Library for PHP
but I cannot find any mention to Google Play applications.
Is there some way to get the downloads of an specific application having the authentification keys?
Thanks in advance!
Use the google-play-scraper library to get an app information as below:
Example:
$app = $scraper->getApp('com.mojang.minecraftpe');
Result:
array (
'id' => 'com.mojang.minecraftpe',
'url' => 'https://play.google.com/store/apps/details?id=com.mojang.minecraftpe',
'image' => 'https://lh3.googleusercontent.com/30koN0eGl-LHqvUZrCj9HT4qVPQdvN508p2wuhaWUnqKeCp6nrs9QW8v6IVGvGNauA=w300',
'title' => 'Minecraft: Pocket Edition',
'author' => 'Mojang',
'author_link' => 'https://play.google.com/store/apps/developer?id=Mojang',
'categories' => array (
'Arcade',
'Creativity',
),
'price' => '$6.99',
'screenshots' => array (
'https://lh3.googleusercontent.com/VkLE0e0EDuRID6jdTE97cC8BomcDReJtZOem9Jlb14jw9O7ytAGvE-2pLqvoSJ7w3IdK=h310',
'https://lh3.googleusercontent.com/28b1vxJQe916wOaSVB4CmcnDujk8M2SNaCwqtQ4cUS0wYKYn9kCYeqxX0uyI2X-nQv0=h310',
// [...]
),
'description' => 'Our latest free update includes the Nether and all its inhabitants[...]',
'description_html' => 'Our latest free update includes the Nether and all its inhabitants[...]',
'rating' => 4.4726405143737793,
'votes' => 1136962,
'last_updated' => 'October 22, 2015',
'size' => 'Varies with device',
'downloads' => '10,000,000 - 50,000,000',
'version' => 'Varies with device',
'supported_os' => 'Varies with device',
'content_rating' => 'Everyone 10+',
'whatsnew' => 'Build, explore and survive on the go with Minecraft: Pocket Edition[...]',
'video_link' => 'https://www.youtube.com/embed/D2Z9oKTzzrM?ps=play&vq=large&rel=0&autohide=1&showinfo=0&autoplay=1',
'video_image' => 'https://i.ytimg.com/vi/D2Z9oKTzzrM/hqdefault.jpg',
)
EDIT: Easily get downloads count as below:
echo $app['downloads']; // Outputs: '10,000,000 - 50,000,000'
Or if you want the left value:
$matches = null;
$returnValue = preg_match('/.*(?= -)/', '10,000,000 - 50,000,000', $matches);
echo $matches[0]; // Outputs: '10,000,000'
Or if you want the right value:
$matches = null;
$returnValue = preg_match('/(?<=- ).*/', '10,000,000 - 50,000,000', $matches);
echo $matches[0]; // Outputs: '50,000,000'
Then easily convert it to integer using:
$count = null;
$returnValue = (int)preg_replace('/,/', '', $matches[0], -1, $count);
echo $returnValue; // Outputs: 10000000 or 50000000
This is about meta data api. You can look at below.
https://developers.google.com/android-publisher/api-ref/reviews
You need to Scrape it. Generally speaking, & of course in this particular case, when the website(here: Google Play) does not provide an API to make your(client's) desired data accessible to him, Web scraping is one of the best methods to gather your required information.
Nearly every piece of information that you can see on a web page, can be scraped. Nowadays with great improvements of web scrapers, not only you are able to grab data from a target website, but also "crawling it like a user", "posting information to website via forms", "logging in as a user" & etc. has become a routine for any web scraper.
There are very strong scrapers out there, like Scrapy(likely the most reputed one, written in Python) almost for every language. AFAIK the best web scraper in PHP, is Goutte written by legendary #fabpot from FriendsOfPHP.
From the Data-Extraction POV, Goutte supports both "CSS Selectors" & XPath (Because it uses Symfony's DOM Crawler as Crawling engine). So you can crawl the document the way you want to extract every piece of information in any hidden corner of a web page!
You can go faraway in scraping with Goutte, But just as a tiny example for grabbing "number of installs" from an ordinary App page in a blink of an eye:
use Goutte\Client;
$Client = new Client();
/**
* #var \Symfony\Component\DomCrawler\Crawler
*/
$Crawler = $Client->request('GET', "https://play.google.com/store/apps/details?id=com.somago.brainoperator&hl=en");
$numberOfInstalls = $Crawler->filter('div.details-section-contents div.meta-info')->eq(1)->filter('div.content')->eq(0)->text();
echo $numberOfInstalls;
It will simply print Brain Operator game's "number of downloads".
This project https://github.com/ArcadiaConsulting/appstorestats is a API in Java to get statistics from Google Play and AppStore
checkout this library 42 matters gives number of downloads , rating many more
With AppID you can get it from the GooglePlay API
Or if the app is yours you can export the statistics from Google Cloud (reference)
In python you can use this.
from google_play_scraper import app #if not installed google_play_scraper then install by **pip install google-play-scraper**
playstore = app('test.example.com');
print(playstore):
On my website, people can register to become a member. Now I want them to be also immediately be subscribed to my MailerLite mailinglist. In the API documentation I have fount the following PHP example which should work:
$ML_Subscribers = new MailerLite\Subscribers('xxxxxxxxxxxxxxxxxxxxxx');
$subscriber = array(
'email' => $e,
'name' => $f,
);
$subscriber = $ML_Subscribers->setId('xxxxxxxxxxx')->setAutoresponders(false)->add($subscriber);
The API url that's mentioned on their website is the following:
https://app.mailerlite.com/api/v1/subscribers/{list_id}/
I am unsure how to implement this URL in the script.. I have the above PHP code that should add a subscriber to the list, but should I also include the link in some way? I could use some help to make it work. Thanks in advance!
When using the MailerLite SDK it is not required to post to any specific end point. There are wrappers within the functions that dictate the endpoint and method request type when sending data to their API.
The provided code below is all that is required:
$ML_Subscribers = new MailerLite\Subscribers( API_KEY );
$subscriber = array(
'email' => $e,
'name' => $f,
);
$subscriber = $ML_Subscribers->setId( LIST_ID )->setAutoresponders(false)->add( $subscriber );
Where you would replace API_KEY with the provided MailerLite API key, and LIST_ID with the ID of the list that you wish to add the subscriber to.
Otherwise if you weren't using their SDK you would need to make a POST to their endpoint: POST https://app.mailerlite.com/api/v1/subscribers/{list_id}/. You would also be required to construct the proper data object to be sent over containing your API Key, an Email and the id of the subscriber list.
You can read further about this in the MailerLite Documentation
Here is my code to select order report from amazon using mws feed api.This is working fine,but now it returns all _GET_ORDERS_DATA_ type reports,but i only need to get the reports having status _DONE_.is it possible to do with PHP?
Here i found an option for ReportProcessingStatusList but i unable to set with this SDk,how to set this option?
$parameters = array (
'Merchant' => MERCHANT_ID,
'MaxCount' => 100
);
$request = new MarketplaceWebService_Model_GetReportRequestListRequest($parameters);
$TypeList = new MarketplaceWebService_Model_TypeList();
$TypeList->setType('_GET_ORDERS_DATA_');
$request->setReportTypeList($TypeList);
First, you are calling GetReportRequestList, which is part of the Reports API, not Feeds API. You can limit results to a specific report type by requesting the list like this:
$request = new MarketplaceWebService_Model_GetReportRequestListRequest(array(
"ReportProcessingStatusList.Status.1": "_DONE_"
));
By the way, besides the API reference documentation, the Scratchpad helps a lot finding and testing out parameters: https://mws.amazonservices.com/scratchpad/index.html (use the proper URL that matches your country/region)
What I'm trying to currently do is fetch Campaign statistics such as Clicks, Impressions, CTR, Average CPC and etc for a particular campaign. Unfortunately, I can't find how to do it via the AdWords API.
What I've found up till now is that,
Maybe, in an earlier version of the CampaignService, we were able to obtain stats by doing something like $campaign->campaignStats. Unluckily, I'm using V201506 and in it there is no campaignStats object/variable.
I probably can get these stats using the 'CAMPAIGN_PERFORMANCE_REPORT' but it needs to be downloaded and I don't want to download the report. I just want an array or something similar returned so that I can process it. Also, I don't want to give any time frame, I just want all time stats to be returned for that campaign. Is it even possible?
If any one could help me out, I would really appreciate it. Kind of been stuck here for a few hours, skimmed through the whole AdWords API documentation but couldn't understand what would be the best and easy approach to this.
Now, Adwords API allowing stats only By reporting service.
And stats can be get using two methods.
1) By using reporting service as described
here
2) You can use Adwords Query Language. See
this
i don't know if you still need this but the API V201806 I found a solution. In this version of API exist the function getAsString() which returns the data in String and not download file, I request data in format XML and in PHP transform the response into a XML Object.
This is code I used:
class DownloadCriteriaReportWithAwql {
public static function runExample(AdWordsSession $session, $reportFormat){
// Create report query to get the data for last 7 days.
$query = (new ReportQueryBuilder())
->select([
'CampaignId',
'AdGroupId',
'Id',
'Criteria',
'CriteriaType',
'Impressions',
'Clicks',
'Cost',
'Conversions'
])
->from(ReportDefinitionReportType::CRITERIA_PERFORMANCE_REPORT)
->where('Status')->in(['ENABLED'])
->duringDateRange(ReportDefinitionDateRangeType::LAST_7_DAYS)
->build();
// Download report as a string.
$reportDownloader = new ReportDownloader($session);
// Optional: If you need to adjust report settings just for this one
// request, you can create and supply the settings override here.
// Otherwise, default values from the configuration
// file (adsapi_php.ini) are used.
$reportSettingsOverride = (new ReportSettingsBuilder())->includeZeroImpressions(false)->build();
$reportDownloadResult = $reportDownloader->downloadReportWithAwql(
sprintf('%s', $query),
$reportFormat,
$reportSettingsOverride
);
//print "Report was downloaded and printed below:\n";
$datos = $reportDownloadResult->getAsString();
return ($datos);
}
public static function main(){
// Generate a refreshable OAuth2 credential for authentication.
$oAuth2Credential = (new OAuth2TokenBuilder())->fromFile()->build();
// See: AdWordsSessionBuilder for setting a client customer ID that is
// different from that specified in your adsapi_php.ini file.
// Construct an API session configured from a properties file and the
// OAuth2 credentials above.
$session = (new AdWordsSessionBuilder())
->fromFile()
->withOAuth2Credential($oAuth2Credential)
->build();
$string = self::runExample($session, DownloadFormat::XML);
$xml = new \SimpleXMLElement($string);
return $xml;}}
The question was asked in 2015, since then they renamed the API to Google Ads API. The current version is V6 where getting clicks, CTR, CPC and other metrics is relatively simple.
The documentation here states:
This page shows all metrics and segments that can be put in the same SELECT clause as the fields of campaign
Based on that the AWQL for getting campaign together with clicks will look like this (tested):
$query = "SELECT campaign.id, campaign.name, campaign.status, metrics.clicks FROM campaign ORDER BY campaign.name"
Example in PHP how to iterate through results:
$stream = $googleAdsServiceClient->searchStream($customerId, $query);
foreach ($stream->iterateAllElements() as $googleAdsRow) {
/** #var GoogleAdsRow $googleAdsRow */
$data['campaigns'][] = [
'id' => $googleAdsRow->getCampaign()->getId(),
'clicks' => $googleAdsRow->getMetrics()->getClicks(),
];
}
Any advice on how to get MySpace or Orkut info such as birthdate from a person's profile using OAuth using the OpenSocial PHP Client library?
I am lost on the process, and the tutorials are complicated. Any simple code would be helpful!
Thanks.
First, you need the PHP Open Social Client.
As shown in the documentation, you will need to create an osapi container, which requires a provider and an authorization object. In the case of MySpace, it would look something like:
$provider = new osapiMySpaceProvider();
$auth = new osapiOAuth2Legged("<consumer key>", "<consumer secret>", "<OpenSocial user ID>");
$osapi = new osapi($provider, $auth);
I'm afraid I have no idea what goes in the auth area, whether it's those actual strings or something that you should already know. I'm sure the page I got it from has more info. But either way, once you have the osapi container, you can then make requests for user info:
$profile_fields = array(
'aboutMe',
'displayName',
'bodyType',
'currentLocation',
'drinker',
'happiestWhen',
'lookingFor'
);
$self_request_params = array(
'userId' => $userId, // Person we are fetching.
'groupId' => '#self', // #self for one person.
'fields' => $profile_fields // Which profile fields to request.
);
$result = $osapi->people->get($self_request_params), 'self');
Here's a nice tutorial: http://wiki.opensocial.org/index.php?title=Social_Website_Tutorial