Facebook Ads API - Can't Edit Audience - php

I'm trying to create custom audience & followed the instructions given here.
This is the code I've used.
$audience = new CustomAudience(null, 'act_'.$account_id);
$aud_data = array(
CustomAudienceFields::NAME => $name,
CustomAudienceFields::SUBTYPE => CustomAudienceSubtypes::WEBSITE,
CustomAudienceFields::RULE => array('event' => array('i_contains' => $name ) ),
CustomAudienceFields::PIXEL_ID => $pixelId,
CustomAUdienceFields::DESCRIPTION => '',
CustomAudienceFields::RETENTION_DAYS => 180,
CustomAudienceFields::PREFILL => True
);
$audience->setData($aud_data);
$create = $audience->create();
The custom audience is being created successfully but on dashboard it is giving the error 'Can't Edit the Audience' as shown in screenshot below.
I don't understand this error. I'm using the latest API, why would it use old settings? Also, this is not what I want, I want to create a 'Custom Combination Audience' which is available through dashboard but not through API. Basically, I'm trying to emulate this (screenshot) through API. I'm using PHP Ads SDK 2.5

1) You're rule should be a JSON string.
CustomAudienceFields::RULE => '{"and": [{"event": {"i_contains": "ViewContent"}},{"content_name": {"i_contains": "'.$name.'"}}]}'
2) Facebook doesn't support that type via the current Marketing API (v2.11):
https://developers.facebook.com/docs/marketing-api/reference/custom-audience/
Type of custom audience, derived from original data source.
Note: COMBINATION subtype is only used by Power Editor and Ads Manager, and not available through the API.

Related

Facebook Custom Audience Marketing API / Graph API giving 200 ok status but doing nothing else

I've been roughly trying for 10 hours now to set up facebook to create custom audiences via POST REQUEST
What I have so far is , I created an app, an access token with some permissions (as stated in the fb docs) which would be:
read_insights ads_management ads_read public_profile
My Goal is: Creating a Custom Audience per API Call , the Data provided for the user comes from me , included in the api call as a JSON object
So i am making the GET Request like this
$client = new Client();
$response = $client->request('GET','https://graph.facebook.com/v5.0/act_<act number>/customaudiences',[
'query' => [
'name' => 'my custom audience',
'subtype' => 'CUSTOM',
'customer_file_source' => 'USER_PROVIDED_ONLY',
'access_token' => '<accesstoken>',
],
]);
and it returns 200 ok , "{"data":[]}"
So it seems that the custom audience has not been created (wanted to create an empty one for now) , what am I doing wrong?
Thanks for the help.
Greetings
The Graph API documentation states that the API call has to be a POST request but you are making a GET request here.
Try this:
$client = new Client();
$response = $client->request('POST','https://graph.facebook.com/v5.0/act_<act number>/customaudiences',[
'query' => [
'name' => 'my custom audience',
'subtype' => 'CUSTOM',
'customer_file_source' => 'USER_PROVIDED_ONLY',
'access_token' => '<accesstoken>',
],
]);
Sapnesh, a thing to keep in mind that to create Offline Custom Audiences you have to first accept terms & conditions in Business manager to be able to do it. Before that you will be getting en error.
Still, you error looks like you access token has insufficient permissions for audience creation. You can make first and Access token with full permissions to debug your requests and get to successful Audience creation and then issue limited access token only for that purpose if you need it.

Build APP using specific keys via Phonegap Build API?

I'm trying to use Phonegap Build API.
I am using this open source PHP library to connect to the Phonegap plugin.
https://github.com/mradionov/phonegap-build-api
Everything works fine as it should.
I can add keys, upload apps and all other general tasks.
However, the issue that I currently have is that I need to be able to upload the app and build it using a specific key for each platform.
To upload the app I use this method:
$res = $api->updateApplicationFromFile(3334534, 'path/to/myapp.zip', array(
'title' => 'The APP title',
// see docs for all options
));
This uploads it correctly and as it should.
Now, i tried to upload the app using the same method but select a specific key to build it with like so:
$res = $api->updateApplicationFromFile(3334534, 'path/to/myapp.zip',
'title' => 'The APP title',
'keys' => 1435671
// see docs for all options
));
But this fails to do anything and I dont see any errors either!
Based on the Phonegap API documentation, we can send the following to the API:
keys":{"ios":123,"android":567,"winphone":72}
the numbers used are the keys/certficates that already uploaded onto the Phonegap system.
Could someone please advice on this issue?
Thanks in advance.
finally found it.
Basically I need to pass the values as an array like so:
'keys' => array("ios" => XXXXXXX, "android" => XXXXXXXX),
So the code looks like this:
$res = $api->updateApplicationFromFile(3334534, 'path/to/myapp.zip',
'title' => 'The APP title',
'keys' => array("ios" => XXXXXXX, "android" => XXXXXXXX),
// see docs for all options
));
And this works just fine...
Hoep this helps others.

Is it possible to get number of downloads of an application from Google Play?

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):

How to use Saved Audience as a targeting Spec when creating Adsets

I am trying to create an adset with targeting specs and assign saved_audience id as a targeting specs. I looked at the API docs of targeting spec: https://developers.facebook.com/docs/marketing-api/targeting-specs/v2.8
It talks about custom_audience but not saved_audience. I tried to send it as a parameter saved_audience, saved_audiences etc. thinking that maybe it is not documented. API response is invalid parameter.
Here is the code:
$set->setData(array(
AdSetFields::NAME => $obj_page->title.' '.time(),
AdSetFields::CAMPAIGN_ID => $campaign_id,
AdSetFields::DAILY_BUDGET => $daily_budget,
AdSetFields::BID_AMOUNT => $daily_budget,
AdSetFields::START_TIME => (new \DateTime($request->start_time))->format(\DateTime::ISO8601),
AdSetFields::END_TIME => (new \DateTime($request->end_time))->format(\DateTime::ISO8601),
AdSetFields::BILLING_EVENT => AdSetBillingEventValues::IMPRESSIONS,
AdSetFields::TARGETING => (new Targeting())->setData(array(
'custom_audiences' => array($audience_id), // works
TargetingFields::PUBLISHER_PLATFORMS => array('facebook'),
TargetingFields::DEVICE_PLATFORMS => array('desktop'),
))
));
using 'saved_audience' => array($audience_id) doesn't work.
There is no way to specify saved_audiences in the targeting spec. For more info on all the possible fields refer to the SDK.
https://github.com/facebook/facebook-java-ads-sdk/blob/master/src/main/java/com/facebook/ads/sdk/Targeting.java
I've been dealing with the same problem (check my Stackoverflow question) and my conclusion is that it isn't possible right now. A work-around is to retrieve the targeting spec from your saved audience in a separate API call and copy over these settings to the new ad you're creating. Disadvantage is that when updating the saved audience, your ad won't be updated.

Uploading a cover photo to a facebook event on creation using the facebook event API

Using the events API I have the following code to post my event with an event photo
$facebook = new Facebook(array(
"appId" => "XXX",
"secret" => "XXX",
"cookie" => false,
"fileUpload" => true
));
$data = array("name"=>$eventTitle,
"start_time"=>$startTime,
"description"=>$description,
"privacy_type"=>$privacyType,
basename($fileName) => '#'.$fileName
);
$result = $facebook->api("/me/events","post",$data);
I'm interested in uploading a cover photo and I haven't found a clear way to do so with the PHP sdk. I've tried "source" => '#'.$coverPhoto, "cover" => '#'.$coverPhoto, "cover_url" => '#'.$coverPhoto and:
$data = array("name"=>$eventTitle,
"start_time"=>$startTime,
"description"=>$description,
"privacy_type"=>$privacyType,
basename($fileName) => '#'.$fileName,
"cover" => array(
"source" => '#'.$coverPhoto
)
);
But I can't seem to find the right way to push in a cover photo. Any ideas?
Unfortunately, you can't do it as of now.
There are two event related endpoints in Graph API: /{event-id} and /{user-id}/events and according to the Graph API documentation, none of them provide a support to upload the Event cover picture. Also, the documentation does not mention anything about support to upload the event photo (which, I assume, you were successfully able to do with your code).
However, based on the official Graph API documentation and my knowledge of Graph API, it's currently not possible to do that.
The method described in the official documentation to upload a cover photo of an event don't work as of now. I've reported this as a bug. You can subscribe to this bug to get any updates regarding the same.
The only way to do this (as of now)-
Firstly, you cant do this upload cover pic while creating an event. You first have to create an event, as a result you'll get the event_id. Use this event_id, to make a call:
\POST /{event-id} with param: cover_url
Code:
$param = array(
'cover_url' => '{image-link}'
);
$facebook->api('/{event-id}', 'POST', $param);

Categories