I am using the Facebook API package to receive detailed information about a new lead from Facebook Lead Ads.
When I use the below
$lead = new \FacebookAds\Object\Lead('77408XXXXXX0968');
$lead->read();
$lead_data = $lead->getData();
This returns
Array
(
[ad_id] =>
[ad_name] =>
[adset_id] =>
[adset_name] =>
[campaign_id] =>
[campaign_name] =>
[created_time] => 2016-09-20T11:33:50+0000
[custom_disclaimer_responses] =>
[field_data] => Array
(
[0] => Array
(
[name] => full_name
[values] => Array
But things like the adset_name are empty. Does anyone have any idea why or how I can populate them?
After searching high and low I ended up posting a issue on the Github page.
https://github.com/facebook/facebook-php-ads-sdk/issues/252
This is the answer.
use FacebookAds\Object\Lead;
use FacebookAds\Object\Fields\LeadFields;
$fields = array(
LeadFields::AD_ID,
LeadFields::AD_NAME,
LeadFields::ADSET_ID,
LeadFields::ADSET_NAME,
LeadFields::CAMPAIGN_NAME,
LeadFields::FIELD_DATA,
);
$lead = new Lead('93xxxxxxxxxxxxx42');
$lead->read($fields);
$lead_data = $lead->getData();
echo $lead_data['created_time']. "\n";
echo $lead_data['ad_id']. "\n";
echo $lead_data['field_data']. "\n";
echo $lead_data['ad_name']. "\n";
echo $lead_data['adset_name']. "\n";
echo $lead_data['campaign_name']. "\n";
Related
I was using marketing Api for facebook and php-facebook-sdk something.
I was able to create a campaign and adset and upload a video and now I'm on the part wherein I need to create AdCreative. I find it hard to look for a video_data with the correct object story spec or something like that, so I tried creating based on information that I gathered accross the net and here's what I came up with.
try {
$fields = array(
);
$params = array(
'url_tags' => 'utm_source=facebook',
'object_story_spec' => array('page_id' => $page_id, 'video_data' => array('call_to_action' => array('type' => 'WATCH_VIDEO')), 'image_url' => $image_url, 'video_id' => $video_id),
'name' => 'My Bolbs',
'applink_treatment' => 'web_only',
);
$creative = (new AdAccount($ad_account_id))->createAdCreative(
$fields,
$params
);
$creative_id = $creative->id;
} catch (Exception $e) {
echo 'Caught exception: ', $e, "\n";
}
The error it was throwing to me was this
["error"]=>
array(8) {
["message"]=>
string(17) "Invalid parameter"
["type"]=>
string(14) "OAuthException"
["code"]=>
int(100)
["error_subcode"]=>
int(1443048)
["is_transient"]=>
bool(false)
["error_user_title"]=>
string(34) "object_story_spec param is invalid"
["error_user_msg"]=>
string(99) "Object story spec is ill formed. Maybe missing Page ID or creative details, or invalid fields exist"
["fbtrace_id"]=>
string(11) "Hmti64698Rr"
}
I was wondering if I can ask for any advice on how to fix this error.
Thanks and advance thank you to all those who will suggest and give advice.
Your 'object_story_spec' array is not formed correctly.
'image_url' and 'video_id' are out of 'video_data' array.
The correct array should be:
'object_story_spec' => array(
'page_id' => $page_id,
'video_data' => array(
'call_to_action' => array('type' => 'WATCH_VIDEO'),
'image_url' => $image_url,
'video_id' => $video_id
)
)
I need to generate a google analytic event from my perl cron job.
Based on https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide
POST to www.google-analytics.com/collect will accept the metrics.
I tried posting metric using following code, but I am not seeing them in google analytics realtime page.
use LWP::UserAgent;
$ua=LWP::UserAgent->new;
$ua->default_header("Content-type" => "application/x-rm-urlencoded");
my $response = $ua->post("http://www.google-analytics.com/collect",
"v" => 1,
"tid" => "UA-XXXXXXXX-Y",
"cid" => 125,
"t" => "pageview",
"dh" => "Cron",
"dp" => "Cron.php",
"dt" => "CronTitle");
print $response->status_line;'
Response is "200 OK", but I am not seeing the data in google analytics webpage.
I am able to post analytics from my php scripts, but could not post analytics from perl script.
I solved my problem as follows.
Created an utility php script and called that php script from my perl script. Then it worked.
<?php
$ec = $_GET['ec'];
$ea = $_GET['ea'];
$el = $_GET['el'];
$ev = $_GET['ev'];
// Send event tracking as well.
$url = 'http://www.google-analytics.com/collect';
$event_data = array(
'v' => '1',
'tid' => 'UA-XXXXXX-Y',
'cid' => $_SERVER["REMOTE_ADDR"],
't' => 'event',
'ec' => $ec,
'ea' => $ea,
'el' => $el,
'ev' => $ev);
$event_options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($event_data),
),
);
$event_context = stream_context_create($event_options);
$result = file_get_contents($url, false, $event_context);
echo "XXX";
?>
im adding news feed pictures in my members site and need help getting the large pictures from the news feed.
This is my code to get the news feed pictures
$json_object = #file_get_contents('https://graph.facebook.com/me/home?access_token=' . $fb_access_token);
$news_feeds = json_decode($json_object, true);
foreach($news_feeds['data'] as $news_feed)
{
echo '<img src="' . $news_feed['picture'] . '" />' . '<br />';
}
This give me the news feed pictures fine but all different sizes.
any help would be good!
I have looked around for a long time and still cant find the answer?
this is a example of a facebook news feed array i am trying to get the large picture from.
[id] => 1423830694520861_1508536172716979
[from] => Array
(
[category] => Public figure
[name] => Dan Bilzerian
[id] => 1423830694520861
)
[to] => Array
(
[data] => Array
(
[0] => Array
(
[category] => Public figure
[name] => Jen Selter
[id] => 244183679061369
)
)
)
[message] => Happy 21st to Jen Selter and her #NeverEndingAss
[message_tags] => Array
(
[14] => Array
(
[0] => Array
(
[id] => 244183679061369
[name] => Jen Selter
[type] => page
[offset] => 14
[length] => 10
)
)
)
[picture] => https://scontent-b.xx.fbcdn.net/hphotos-xpf1/v/t1.0-9/p130x130/10563168_1508536129383650_2440015247017447728_n.jpg?oh=bfdb86c35b4b0ffe5a4ad9dbe65aba59&oe=54688CA7
[link] => https://www.facebook.com/danbilzerianofficial/photos/a.1425329161037681.1073741829.1423830694520861/1508536129383650/?type=1&relevant_count=1
[icon] => https://fbstatic-a.akamaihd.net/rsrc.php/v2/yx/r/og8V99JVf8G.gif
I belive I have to change the _n.jpg to _b.jpg
or p130x130 to b740x740 but the function is not working ??
I have tryed running this function before/after the foreach loop. But it is still not working?
$news_feed ['picture'] = str_replace("_n.jpg", "_b.jpg", $news_feed['picture']);
also this
$news_feed ['picture'] = str_replace("p130x130", "b740x740", $news_feed['picture']);
can some one please help, :( thanks
Try object_id ....it worked for me :)
echo '<img src="https://graph.facebook.com/' . $news_feed['object_id'] . '/picture?type=normal">' . '<br />';
Is it?
Uploading works like a charm, but I don't want it to show up on timeline or feed.
I've tried adding no_story to each request, and to the $params which is commented out in following code:
foreach ($data['Ad']['Media'] as $medium) {
$file = $medium['tmp_name'];
$req = array(
'method' => 'POST',
'relative_url' => '/me/photos',
'message' => $data['Ad']['title'],
'attached_files' => 'file' . $count,
'no_story' => 1 //Also tried 'true'
);
//add this request to batch
$batch[] = json_encode($req);
$params['file' . $count] = '#' . realpath($file);
$count++;
}//foreach
$params['batch'] = '[' . implode(',', $batch) . ']';
//$params['no_story'] = true;
Edit ##
See comment below.
i know you may not need the answer any more, but i was facing same issue , and after a lot of try and error i figured it out so i will post the answer may be some one face this issue again
$req = array(
'method' => 'POST',
'relative_url' => '/me/photos',
'attached_files' => 'file' . $count,
'body' => 'no_story=1'
);
I am storing the linkedin access token in database. This is the token that is stored in my database:
oauth_token=xxxxxxxxxxxxxxxxxxx&oauth_token_secret=xxxxxxxxxxxxxxxxxxx&oauth_expires_in=5183998&oauth_authorization_expires_in=5183998
I want to retrieve the linkedin connections using this access token. I am trying to make a call like this:
$a = new Zend_Oauth_Token_Access();
$client = $a->getHttpClient( array(
'siteUrl' => LIN_SITE_URL,
'callbackUrl' => LIN_SITE_CALLBACK_URL,
'requestTokenUrl' => LIN_REQUEST_TOKEN_URL,
'userAuthorizationUrl' => LIN_USER_AUTHORIZATION_URL,
'accessTokenUrl' => LIN_ACCESS_TOKEN_URL,
'consumerKey' => LIN_CONSUMER_KEY,
'consumerSecret' => LIN_CONSUMER_SECRET
) );
$client->setUri('http://api.linkedin.com/v1/people/~/connections:(id,first-name,last-name,picture-url)');
$client->setParameterGet('token',$linToken);
$client->setMethod(Zend_Http_Client::GET);
$response = $client->request();
$content = $response->getBody();
$data = json_decode(Zend_Json::fromXml($content, false));
print_r($data); echo "<br/>";
The error i am getting here is:
stdClass Object ( [error] => stdClass Object ( [status] => 404 [timestamp] => 1349429996351 [request-id] => 8U8A1UNF1V [error-code] => 0 [message] => Could not find person based on: ~ ) )
Is this the correct way to make a call or am i doing something wrong here. I am using zend framework.
Thanks.
I was able to solve the problem by passing the outh_token and outh_token_secret as an array to the setParams() of Zend_Oauth_Token_Access as below:
$a = new Zend_Oauth_Token_Access;
$a->setParams(array(
'oauth_token' => 'xxxxxxxxxxxxxxxxxxxxxxxxxx',
'oauth_token_secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'
));
In your code example I don't see where you're setting the access token and secret. I just see that you're instantiating the $a variable:
$a = new Zend_Oauth_Token_Access();
Are you retrieving the access token and secret from you database then setting it to the $a variable? Something like this:
$a->setToken($row['token'])
->setTokenSecret($row['secret']);
By the way, this is a good reference for using Zend and LinkedIn: http://www.contentwithstyle.co.uk/content/linkedin-and-zendoauth/