I am using the Facebook marketing api to create a campaign, adset, creative and ads and I am using the PHP sdk 3.0 to manage them in Facebook.
I can create them successfully. Here is code to create a campaign:
$fields = array();
$params = array(
'name' => 'API Test - vish',
'objective' => 'CONVERSIONS',
'status' => 'PAUSED',
);
try{
$campaign = $this->ad_account->createCampaign($fields,$params);
} catch (Exception $e) {
throw new Exception($e->getMessage());
}
echo $campaign->id;
I want to update details of a campaign.
I did some research and found this link, which states, that it is possible to update campaign details, but it does not provide a correct way to do it.
Anybody please let me know how I can update Facebook campaign details using its api.
I know it is old question but I had the same issue and I've solved it this way:
$campaign = new Campaign($campaignId);
$campaign->updateSelf($fields, $params); // in $params are updated properties
Maybe it will help someone.
Related
I have a store in Dutchie.com. I want to access it's products using API key.
This has to do via Dutchie API using GraphQL integrated with PHP.
This is the Sample API Key:
public-eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJBUEktQ0xJRU5UIiwiZXhwIjozMzE4NjM5Mjc0NSwiaWF0IjoxNjI5NDgzOTQ1LCJpc3MiOiJodHRwczovL2R1dGNoY29tIiwianRpIjoiNGMtOTMyOC00MjhkLWEyYTMtOWQzMTc2ZTUwODY0IiwiZW50ZXJwcmlzZV9pZChLWExYTctNDM3OC05NWY4LTNlYzVzBiNSIsInV1aWQiOiI0M2ZlMjdkNy1iZWU2LTQxOTgtYWNhMi03N2Y5Y2I3MjI5MGIifQ.hCQWpcQ5uhKnZOSVQDA5SCMkx5kopC7H3upeU-1jMpg
This is the GraphQL Ping mutation.
mutation Ping {
ping {
id,
time
}
}
Dutchie End Point: https://plus.dutchie.com/plus/2021-07/graphql
http header parameter
{
"Authorization":"Bearer API KEY HERE"
}
Ping output
Basically I want to run GraphQL query in my PHP page. I'll add into my WordPress page later.
I have tried php-graphql-client php library.
Can someone help me to do this using above library or another one really appreciate. I wasted too much time for this as I have only few knowledge of GraphQL.
This is the code what I have tried.
$client = new Client(
'https://plus.dutchie.com/plus/2021-07/graphql',
['Authorization => Bearer API Key here']
);
// Create the GraphQL mutation
$gql = (new Mutation('Ping'))
->setSelectionSet(
[
'id',
'time',
]
);
// Run query to get results
try {
$results = $client->runQuery($gql);
}
catch (QueryError $exception) {
// Catch query error and desplay error details
print_r($exception->getErrorDetails());
exit;
}
// Display original response from endpoint
var_dump($results->getResponseObject());
// Display part of the returned results of the object
var_dump($results->getData()->pokemon);
// Reformat the results to an array and get the results of part of the array
$results->reformatResults(true);
print_r($results->getData()['data']);
Error what I got.
https://github.com/guzzle/psr7/blob/master/src/MessageTrait.php
Instead of:
$client = new Client(
'https://plus.dutchie.com/plus/2021-07/graphql',
['Authorization => Bearer API Key here']
);
Try
$client = new Client(
'https://plus.dutchie.com/plus/2021-07/graphql',
['Authorization' => 'Bearer API Key here']
);
There seems to be an issue for getting all Adwords campaigns. When I currently try to retrieve all campaigns, I don't get the video campaigns. My understanding through the documentation was that it shouldn't be this much work. Another SO user had the similar problem Whats happens with GET Video Adwords Campaigns
Is this a Google Adwords error, deprecation error, or something that I messed up on my end?
require_once('Google/Api/Ads/AdWords/Lib/AdWordsUser.php');
$oauth2Info = array('client_id' => $client_id, 'client_secret' => $client_secret, 'access_token' => $access_token);
$user = new AdWordsUser();
$user->SetDeveloperToken($developer_token);
$user->SetOAuth2Info($oauth2Info);
$customerService = $user->GetService('CustomerService', 'v201509');
$customer = $customerService->get();
$user->SetClientCustomerId($customer->customerId);
$campaignService = $user->GetService('CampaignService', 'v201509');
$selector = new Selector();
$selector->fields = array('Id', 'Name');
$selector->ordering[] = new OrderBy('Name', 'ASCENDING');
$selector->paging = new Paging(0, 500);
$page = $campaignService->get($selector);
The page value only contains non-video campaigns. I'm in the process of upgrading API, so maybe it can't get videos for API version v201509?
Google Adwords API does not currently support video campaigns.
You can collect some data thanks to the video performance report : https://developers.google.com/adwords/api/docs/appendix/reports/video-performance-report.
This is the only data you can get on TrueView (video Adwords) through the API.
I am adding AWeber as an autoresponder in a web application. Using AWeber API, I am able to add a new subscriber to list with a known name which is in this case is firstlist:
$app = new MyApp();
$app->findSubscriber('whtever#aol.com');
$list = $app->findList('firstlist');
$subscriber = array(
'email' => 'someemail#gmail.com',
'name' => 'Name here'
);
$app->addSubscriber($subscriber, $list);
Function definition for findList() is:
function findList($listName) {
try {
$foundLists = $this->account->lists->find(array('name' => $listName));
return $foundLists[0];
}
catch(Exception $exc) {
print $exc;
}
}
As I am developing a public application, so I need to provide users an option to select from their available lists.
Please guide me how I can retrieve all the lists name.
You are returning $foundLists[0] so it will return single list. Try to return foundLists and check what it returns.
This may help you: https://labs.aweber.com/snippets/lists
In short, I pulled the lists by first finding the Aweber User Id so that I could use it in the URL https://api.aweber.com/1.0/accounts/<id>/lists
To find the User ID, I first got the account.
$this->aweber->getAccount($token['access'], $token['secret']);
Then, I retrieve the user's information.
$aweber_user = $this->aweber->loadFromUrl('https://api.aweber.com/1.0/accounts');
From that, I grabbed the user ID with...
$id = $aweber_user->data['entries'][0]['id'];
Once I had the user ID, I could then retrieve their lists with...
$lists = $this->aweber->loadFromUrl('https://api.aweber.com/1.0/accounts/'.$id.'/lists');
This example is more of a procedural approach, of course, I recommend utilizing classes.
Does anyone know how to fetch all facebook ads statistics and display on webpage using Facebook Ads Api-PHP SDK. I am using this API and I am getting campaign details like name of campaign, id, status. but not able to get impressions,clicks, spent.
What I am doing let me share with you:
1) I am getting access token by authorizing user
2) After getting access token, I am using below code
$account = new AdAccount('act_XXXXXXXXXXXXXXX');
$account->read();
$fields = array(
AdCampaignFields::ID,
AdCampaignFields::NAME,
AdCampaignFields::OBJECTIVE,
);
$params = array(AdCampaignFields::STATUS => array(AdCampaign::STATUS_ACTIVE,AdCampaign::STATUS_PAUSED,),);
$campaigns = $account->getAdCampaigns($fields, $params);
/* Added By Jigar */
$campaign = new AdCampaign('XXXXXXXXXXXXXXXX');
$compainDetails = $campaign->read($fields);
3) then printing the array
echo "<pre>";
print_r($compainDetails);
exit;
If anyone know any suggestion in above code, please share. All code is in PHP. Dose anyone have any tutorial that fetch all above required data then share it
You could try to use the facebook insights api instead of $campaign->read. Here's an example:
https://developers.facebook.com/docs/marketing-api/insights/v2.5#create-async-jobs
What you have to do to get impressions, click and spent is to add these fields to the $fields param. In your case, the complete code should look like the following:
use FacebookAds\Object\Campaign;
use FacebookAds\Object\Values\InsightsLevels;
use FacebookAds\Object\Values\InsightsFields;
$campaign = new Campaign();
$fields = array(
InsightsFields::IMPRESSIONS,
InsightsFields::UNIQUE_CLICKS,
InsightsFields::CALL_TO_ACTION_CLICKS,
InsightsFields::INLINE_LINK_CLICKS,
InsightsFields::SOCIAL_CLICKS,
InsightsFields::UNIQUE_SOCIAL_CLICKS,
InsightsFields::SPEND,
);
$params = array(
'level' => InsightsLevels::CAMPAIGN,
);
$async_job = $campaign->getInsightsAsync($fields, $params);
$async_job->read();
I don't know what exactly the "click" param means for you, but if you take a look at all these click params, I'm sure you'll find it or you'll know how to calculate it.
For a complete list of fields available on insights objects, have a look at: https://github.com/facebook/facebook-php-ads-sdk/blob/master/src/FacebookAds/Object/Fields/InsightsFields.php
Hope that helps.
Regards, Benjamin
I have a Facebook App that allows users to upload pictures from my website to my Facebook page. I would like to know who uploaded the pictures and after some research I managed to get this following PHP code:
$args = array(
'message' => $fbme['name'].' will have a love marriage.',
'image' => '#' . realpath('./images/wall-e-and-eva1.jpg'),
);
$data = $facebook->api('/'.$uid.'/photos', 'post', $args);
My output is suppose to be on the lines of Adam Smith will have a love marriage unfortunately the only output I am getting is will have a love marriage.
How can I get the value of $fbme['name'] - can you give me a pratical example of code please?
Thanks.
You can use the graph api to fetch basic information (including name) of your authenticated users
try {
$fbme = $facebook->api('/'.$uid); // $fbme['name'] will be the user's name
// put rest of your code below
} catch (FacebookApiException $e) {
// handle errors
}