Facebook API Get Ad Account Ad Spend - php

I'm attempting to just get the spend for specific Ad Accounts from the previous day. Whenever I send up the request:
$api = Api::instance();
$account = new AdAccount('act_<account_id>');
$params = array(
'level' => 'account',
'date_preset' => 'yesterday',
'fields' => ['spend', 'account_id'],
);
$insights = $account->getInsights(array(), $params);
print_r($insights);
I get a large protected object back and can't seem to find any documentation as to how to access the actual requested data.

//Get HLG Ad Spend
$account = new AdAccount('act_10153795481711178');
$params = array(
'level' => 'account',
'date_preset' => 'yesterday',
'fields' => ['spend', 'account_id']
);
$insights = $account->getInsights(array(), $params);
$hlgData = $insights->getResponse()->getContent()['data'];
if(isset($hlgData[0]))
{
$hlgSpendFB = $hlgData[0]['spend'];
}else{
$hlgSpendFB = "0";
}
Above is how I was able to get the data from the Ad Account for spend from previous day. After digging through the object itself I was able to find the getter functions that procured the data requested.

Related

Zoom Api - I can't update a meeting

I am trying to update a meeting using Zoom API but I can't get it to work. I'm trying to do a PATCH request using eleague oauth2 client like this:
require '../vendor/autoload.php';
require_once '../config.php';
$id = $_POST['id'];
$topic = $_POST['topic'];
$type = $_POST['type'];
$start_time = $_POST['start_time'];
$duration = $_POST['duration'];
$agenda = $_POST['agenda'];
$params = array(
'topic' => $topic,
'type' => $type,
'start_time' => $start_time,
'duration' => $duration,
'agenda' => $agenda,
'password' => '123456'
);
$provider = new \League\OAuth2\Client\Provider\GenericProvider([
'clientId' => CONEXAO_API['clientId'],
'clientSecret' => CONEXAO_API['clientSecret'],
'redirectUri' => CONEXAO_API['redirect_url'],
'urlAuthorize' => 'https://zoom.us/oauth/authorize',
'urlAccessToken' => 'https://zoom.us/oauth/token',
'urlResourceOwnerDetails' => 'https://api.zoom.us/v2/users/me'
]);
$options['body'] = json_encode( $params );
$options['headers']['Content-Type'] = 'application/json';
$options['headers']['Accept'] = 'application/json';
$request = $provider->getAuthenticatedRequest( 'PATCH',
'https://api.zoom.us/v2/meetings/'.$id,
unserialize($_SESSION['token']),
$options
);
$retorno = $provider->getParsedResponse($request);
var_dump($retorno);
I'm getting an empty response, and I'm not sure what is missing. Can anyone help me?
basically the response given by the api is blank or just meeting updated which isn't in json format. So in case you want to check whether its working go to zoom meeting panel and open the meeting which you are updating using api and run the api and check the meeting is updated in zoom meeting panel.
The problem is that the method getParsedResponse for some reason is not returning any message. But the script is working, it's updating the meeting the way it supposed to.
If I get the response using the method getResponse I can see the statusCode 204, which means that everything went ok.

500 error when trying to add new order in TradeGecko API

Pretty specific problem, but I'll lay it out as best I can.
I can easily make a POST request to the TradeGecko API (detailed here: http://developer.tradegecko.com/) and get variant prices in return, that part of the interaction is working smoothly.
However, I'm trying to create a new order and I feel like I'm missing something!
Here's what I have:
<?php
$authorizeUrl = 'https://api.tradegecko.com/oauth/authorize';
$accessTokenUrl = 'https://api.tradegecko.com/oauth/token';
$clientId = <MY_CLIENT_ID>;
$clientSecret = <MY_CLIENT_SECRET>;
$redirectUrl = <REDIRECT_URI>;
// https://github.com/adoy/PHP-OAuth2
require("Client.php");
require("GrantType/IGrantType.php");
require("GrantType/AuthorizationCode.php");
$client = new OAuth2\Client($clientId, $clientSecret, OAuth2\Client::AUTH_TYPE_AUTHORIZATION_BASIC);
$client->setCurlOption(CURLOPT_USERAGENT,$userAgent);
$client->setAccessToken(<MY_ACCESS_TOKEN>);
$client->setAccessTokenType(OAuth2\Client::ACCESS_TOKEN_BEARER);
$params =
array('order' =>
array(
'company_id' => '12345',
'shipping_address_id' => 1,
'billing_address_id' => 1,
'status' => 'active',
'issued_at' => '10-04-2016',
'order_line_items' => array(
array('variant_id' => 123456,
'quantity' => 2),
array('variant_id' => 123457,
'quantity' => 2)
)
)
);
$response = $client->fetch('https://api.tradegecko.com/orders', false, $params);
print_r($response);
?>
I'm hoping that there's something in that code that someone else might spot, I've been staring at it for the better part of 6 hours now, and I can't figure out why this won't go through.

HORDE Imap PHP client - how to fetch messages

Okay, had no luck with the ZETA email client, so now I tried installing the Horde IMAP Client library. I've managed to login to my account, and make a search for e-mails, also got back the results, but I don't know how to fetch the email data, and the documentation is not really helping:|
I presume that I would have to use the Horde_Imap_Client_Base::fetch() method to get some e-mails, which accepts two parameters, a mailbox name, and a Horde_Imap_Client_Fetch_Query object, but I don't know how to get this second object:|
Should this object be returned by one of the Base functions, or should I build this object with the query parameters I want? If the second, how should I rebuild my search query in the fetch query object from the below example?
Here's how I am searching my INBOX, for mails from a specific contact on a specific day:
$client = new Horde_Imap_Client_Socket(array(
'username' => 'my.email#address.com',
'password' => 'xxxxxxxxxx',
'hostspec' => 'my.mail.server',
'port' => '143',
'debug' => '/tmp/foo',
));
$query = new Horde_Imap_Client_Fetch_Query();
$query->dateSearch(new Date(), Horde_Imap_Client_Search_Query::DATE_ON);
$query->headerText("from","mycontact#contact.email");
$results = $client->search('INBOX', $query);
The Horde_Imap_Client_Base::search() returns an array, which contains the search results(the message id's of the searched emails), and some additional data.
Not completely answering your questions. This is how I search for messages which are not deleted.
$client = new Horde_Imap_Client_Socket(array(
'username' => $user,
'password' => $pass,
'hostspec' => $server,
'secure' => 'ssl'
));
$query = new Horde_Imap_Client_Search_Query();
$query->flag(Horde_Imap_Client::FLAG_DELETED, false);
$results = $client->search('INBOX', $query);
foreach($results['match'] as $match) {
$muid = new Horde_Imap_Client_Ids($match);
$fetchQuery = new Horde_Imap_Client_Fetch_Query();
$fetchQuery->imapDate();
$list = $client->fetch('INBOX', $fetchQuery, array(
'ids' => $muid
));
var_dump($list);
}
$results = $client->search($mailbox, $searchquery, array('sort' => array($sSortDir, $sSort)));
$uids = $results['match'];
for ($i = $i_start; $i < $i_to; $i++)
{
$muid = new Horde_Imap_Client_Ids($uids->ids[$i]);
$list = $client->fetch($mailbox, $query, array(
'ids' => $muid
));
$flags = $list->first()->getFlags();
$part = $list->first()->getStructure();
$map = $part->ContentTypeMap();
$envelope = $list->first()->getEnvelope();
}

Facebook Marketing API - How to get number of app installs

I am using the Marketing API, the Insights Edge specifically, to retrieve the data of our campaigns.
https://developers.facebook.com/docs/marketing-api/insights/v2.4
The problem is that I do not see the field for knowing how many app installs the ad has generated.
I see "clicks, impressions, reach" fields but nothing about the number of downloads from the stores.
Is there a way to know that? This is available in the Facebook Ads dashboard but I do not see any way to get that value from the API.
Thanks for any help!!
require_once(__DIR__ . "/config/config.php");
include_once(__DIR__ . "/inc/helpers.php");
require __DIR__ . '/vendor/autoload.php';
use FacebookAds\Api;
use FacebookAds\Object\AdAccount;
use FacebookAds\Object\AdCampaign;
use FacebookAds\Object\Values\InsightsPresets;
$access_token = readFromFile(__DIR__ . "/auth/token.txt");
// Initialize a new Session and instanciate an Api object
Api::init($app_id, $app_secret, $access_token);
// The Api object is now available trough singleton
$api = Api::instance();
$account = new AdAccount('act_' . $ads_account_id);
$campaigns = $account->getAdCampaigns(array(
\FacebookAds\Object\Fields\AdCampaignFields::ID,
\FacebookAds\Object\Fields\AdCampaignFields::NAME,
)
);
foreach ($campaigns as $campaign) {
//echo $campaign->{\FacebookAds\Object\Fields\AdCampaignFields::ID}.PHP_EOL;
$campaign_insights = new AdCampaign($campaign->{\FacebookAds\Object\Fields\AdCampaignFields::ID});
$params = array(
'date_preset' => InsightsPresets::YESTERDAY,
/*
'time_range' => array(
'since' => '2015-08-03',
'until' => '2015-08-03'
),
*/
'filtering' => array(
[
'field' => 'campaign.objective',
'operator' => 'IN',
'value' => ["MOBILE_APP_INSTALLS"]
]
)
);
$insights = $campaign_insights->getInsights(array(
'reach',
'impressions',
'clicks',
'call_to_action_clicks',
'total_actions',
'spend'
), $params);
After trying every possibile field, I have found out that it's inside the "actions" field.
Thanks

Mailchimp intergration error

We want to import all our database into one of your lists. We use php. The code is:
$api_key = "dXXXXXXX7eX276XXXXXXXX490";
$list_id = "7XXXb0XXXe";
$Mailchimp = new Mailchimp($api_key);
$Mailchimp_Lists = new Mailchimp_Lists($Mailchimp);
$batch = array();
$batch[] = array('email' => array(
'email' => 'xxxgmail.com',
"euid" => "xxx#gmail.com",
"leid" => "xxx#gmail.com"
),
'merge_vars' => array('FNAME' => 'XXX'));
$subscriber = $Mailchimp_Lists->batchSubscribe($list_id, $batch, false, true, true);
But I get an error
Mailchimp_User_DoesNotExist
Could not find user record with id
I tried many times, removed uuid and leid but no success. What is wrong? Thank you!
The API key used by me was incorrect.

Categories