Geotargeting Page Posts with the Facebook API - php

I'm trying to geotarget wall posts to my fan page using the Facebook PHP SDK.
The following snippet successfully posts a message to my wall, but the geotargeting isn't taking.
I'm new to programming and I've done my best to follow the documentation here but it's pretty sparse -- I'm not confident that my syntax is correct.
Any help would be very much appreciated.
//compiling the geotargeting parameters
$geoTarget = "{'cities':'Richmond,VA','regions':'Virginia','countries':'US'}";
//my arguments
$args = array(
'access_token' => $page_access_token,
'message' => "this is my message",
'targeting' => $geoTarget
);
//posts the message
$facebook->api("/$page_id/feed","post",$args);

The field is privacy in the Post table
The description field may contain a comma-separated lists of valid country, city and language if a Page's post targeting by location/language is specified.
http://developers.facebook.com/docs/reference/api/post/

To make this easier this is the bit you need http://developers.facebook.com/docs/reference/api/page/#targeting
this will give the info on how to target regions too.
http://developers.facebook.com/docs/reference/ads-api/get-autocomplete-data/
What you need to complete the targeting in the question would be:
The countries bit was right.
Virginia's region code is 51 (which you can find by searching _">https://graph.facebook.com/search?q=vi&type=adregion&match_country_code=true&country_list=US&access_token=_)
Richmond's city id is 2538983 (which you can find by searching _">https://graph.facebook.com/search?q=richmon&type=adcity&limit=150&access_token=_)
so the geotarget would be
$geoTarget = "{'cities':[2538983],'regions':[51],'countries':'US'}";

Related

Set Description, Draft and Permalink using Blogger API with PHP

I really need your help with this matter. I'm looking for a solution for about 3 months now, but really the Blogger API is not easy to deal with because Blogger don't even provide examples.
I can create and publish new posts with PHP script and I have done all things, but I can't set the Post's description, permalink, or even making the new post as draft.
The following is a piece of my code that creating the post.
<?php
$mypost = new Google_Post();
$mypost->setTitle('My Post Title');
$mypost->setContent('This is My Content');
$mypost->setLabels( array( 'News','Weather', 'Media' ) );
$mypost->setCustomMetaData('My_CUSTOM_META_DATA' . time()); // Nothing changed
$mypost->setcustomMetaData('This is the description for you'); //Nothing Changed
$mypost->setDescription('New Description'); // Nothing Changed
$mypost->setUrl('testseturl'); // Nothing Changed
$mypost->setPublished('2021-08-27T23:07:00-07:00'); // Worked as Schedule post
$data = $blogger->posts->insert('My BlogID', $mypost);
echo "<pre>";
var_dump($data);
echo "</pre>";
?>
As you can see I can't set the permalink and I tried several thing such as adding the full URL, and also adding only the custom permalink text + html, but I failed.
I tried also the description several times, but every time I found the description's post empty.
Also I can' set the post as Draft and I have to do this manually from the blog itself.
Blogger doesn't provide any help docs for PHP, and the new Beta client library on github is for all Google products and I wasn't able to use it. I use the library Google API PHP Client 0.6.7 found here although it's deprecated.
The only topic I found in this blog, and it's the same code that I use, but he didn't mentioned anything about permalink, draft, or description.
Please help me as you can.
Thanks.
permalink
Unfortunately there is no way to set custom permalink to the posts using Blogger api, even the official "Try this API" tool don't have this feature, your code is fine it's just Blogger don't support it.
custom description
I don't think there is a way to add custom description as well, setDescription is not a valid method, you can check all the supported methods here
draft post
to create a post draft you can do it like this
$optParams = array('isDraft' => true);
$data = $blogger->posts->insert('My BlogID', $mypost, $optParams);

Reviews in Google API

I am using below code to find Google reviews for property. What I am trying to do is, I am fetching review for property then I will compare it with old review of that property (which is in the DB). If it is greater than the system's property, then it sends email.
This file is run for every hour(as a cron file) and i enable the billing in Google API, so max limit is 1,50,000.
But for some reason API does not return the exact count of reviews.
For example:
I run this file for the one property which has 4 reviews, but API returns 0 for 2 or 3 times then after some time it returns 4 reviews.
I don't know the reason behind it. I also noticed that we can see the reviews on google search page and in Google+. Same you can write reviews in multiple places, like in Google+ and in Google Map.
And to check reviews, I am using google plus url. So is it possible that the review does exist, but in another area(like in Google search page but not in Google+)?
/* call api to get review count of Google */
$url = "https://maps.googleapis.com/maps/api/place/details/json?";
$params = array(
"placeid" => $google_place_id,
"key" => $google_api_key
);
$url .= http_build_query($params);
$resjson = file_get_contents($url);
$msg = $resjson;
Yii::log($msg,'info', 'application');
$resjson = json_decode($resjson,true);
$review_count = $resjson['result']['user_ratings_total']=='' ? 0 : $resjson['result']['user_ratings_total'];
/* If review is greater than 0 then check old review and if it's not same then send email */
if($review_count>0)
{
if(sizeof($ressql)>0)
{
/* if google plus review is greater then system's google+ review then send email */
if($review_count>trim($ressql[0]['google_plus_review']))
{
$this->send_googleplusmail($prop_id);
$msg = "Google+ Review for property id (Mail Sent):".$prop_id." , New Review:$review_count, Old Review: ".$ressql[0]['google_plus_review'];
Yii::log($msg,'info', 'application');
}
}
}
$sql=" INSERT INTO tbl_review_alert (propertyid, google_plus_review) VALUES ";
$sql.="('{$prop_id}','{$review_count}')";
$sql.=" ON DUPLICATE KEY UPDATE propertyid= {$prop_id},google_plus_review= {$review_count}";
$this->insert_review($sql);
My Question is:
(1) Is it possible that the review does exist, but in another area(like in Google search page but not in Google+)? If yes, then in this case can i obtain the URL where review is posted?
(2) Are all of the reviews are sync in Google?
(3) Or i am doing something wrong in my code?
I think I've spot where the problem is.
The reason why you can't see the existing reviews about that Place is that it seems that there're 2 google+ accounts for the same; The only difference (at least the first I've noticed) is in the zip code, MA 02116 vs. MA 02111.
Take a look at:
https://plus.google.com/101511264527346460079/about
and
https://plus.google.com/105917345931375838754/about
As you can see, in the second one there are the same reviews you see in
the search page
And by inserting the address "The Kensington, 665 Washington St, Boston, MA 02116, Stati Uniti" into the finder, I obtain a placeid different from the other one.
Now by using this last one in
$params = array(
"placeid" => $google_place_id, // the new placeid here
"key" => $google_api_key
);
I can then get the 5 reviews in the Place API json response.

Retrieving Posts from Tumblr

I've tried to do my research regarding this topic but the more digging I do, the more confused I'm getting - seems like the documentation on Tumblr's API is all over the place (and fairly dated?); so perhaps someone out there will have some advice for me.
All I'm trying to do is to snag my most recent Tumblr posts and display them on the main page of my website; nothing too fancy. I don't need to POST to tumblr, I just need the info; the idea is that the team I'm working with would like to use Tumblr as a sort of poor-man's CMS while maintaining their presence on the Tumblr site proper.
I can easily retrieve posts using PHP and SimpleXML (http://username.tumblr.com/api/read) - but this doesn't offer too much support outside simple text posts (Other content, like video, photosets, etc - post differently); and it doesn't really seem like an officially supported method of accessing tumblr data (or..maybe it is?). Tumblr itself points folks towards tumblr.php, but I for the life of me can't figure out how to set it up since there's no real documentation for someone just starting to dabble. Some posts on StackOverflow say Tumblr.php doesn't work anymore and point folks to tumblrOauth.php, but I'm running into the same problem. No real 'new to API' documentation. I know how to set up my 'app' in Tumblr - I just don't know how all the Github files (for both of these systems) communicate to each other/the page...
Anyone have any advice? I'm just looking for a point in the right direction, maybe an initial nudge on how to hook the bits up?
Much thanks e-friends!
Hey I've used a few API's but not the Tumblr API, after reading through this page: http://www.tumblr.com/docs/en/api/v2 I'm pretty sure I understand how to set this up so I'll have a go at explaining and you can let me know if you have some success
(Removed code, that PHP API is awful)
EDIT: Original edit removed
Right since the Tumblr PHP Client is rubbish I've had a look myself and just designed a little snippet of code to solve the problem here and retrieve your latest posts in an array that will give you like so:
Array
(
[0] => Array
(
[id] => 49867777007
[type] => photo
[description] =>
[date] => 2013-05-07 18:28:41 GMT
[short_url] => http://tmblr.co/Z5XfMxkSMUFl
[caption] =>
[photo_url] => http://31.media.tumblr.com/a13494fb3cda1e40ab39211973a094f9/tumblr_mm0038sZGH1qdlh1io1_400.gif
[width] => 395
[height] => 350
)
Use this code and then go through your $myposts later on the page
<?php
$apikey = "your_api_key";
$limit = 10;
$tumblr = "your.tumblr.com";
$apidata = json_decode(file_get_contents("http://api.tumblr.com/v2/blog/$tumblr/posts?api_key=$apikey&limit=$limit"));
$mypostsdata = $apidata->response->posts;
$myposts = array();
$i = 0;
foreach($mypostsdata as $postdata) {
$post['id'] = $postdata->id;
$post['type'] = $postdata->type;
$post['description'] = $postdata->description;
$post['date'] = $postdata->date;
$post['short_url'] = $postdata->short_url;
$post['caption'] = $postdata->caption;
$post["photo_url"] = $postdata->photos[0]->original_size->url;
$post["width"] = $postdata->photos[0]->original_size->width;
$post["height"] = $postdata->photos[0]->original_size->height;
$myposts[$i] = $post;
$i++;
}
// Then handle $myposts later on your page
echo '<pre>'.print_r($myposts).'</pre>';
// There's quite a lot more data you can use so if you want
// to print out $mypostsdata then you might find any more data you need
?>
Sorry the previous suggestions didn't work, the PHP Client really is awful but let me know if that's enough or if you need some revision to it

how to tag a friend using FB graph API?

I am trying to tag a friend in FB message to be posted, I am using PHP, and for FB I am using FB Auth API 2.0, I have tried to get related information from facebook developers forum, however can't find enough information for this one.
Can anyone suggest me from where to get started for this? any links to related documentation or forum links using which I can get started?
You use the message_tags field of the Post object. Check out the docs:
message_tags: object containing fields whose names are the indexes to
where objects are mentioned in the message field; each field in turn
is an array containing an object with id, name, offset, and length
fields, where length is the length, within the message field, of the
object mentioned
Something like this:
$facebook->setFileUploadSupport(true);
$tags = array(
‘tag_text’ => ‘ak Yip’,
‘tag_uid’ => 642536423,//it’s my id on facebook as a sample
‘x’ => 10,
‘y’ => 10,
);
$args['tags'] = array($tags);
$args['image'] = ‘#’ . realpath($fn);
$data = $facebook->api(‘/me/photos’, ‘post’, $args);
Note:
**One:Your app need to get permissions like ‘user_photo_video_tags’ and ‘friends_photo_video_tags’.
Two:X,Y is proportion, not coordinate. Don’t put value over 100.**

How to mail to a static list segment with mailchimp API

Once I've identified identified the email addresses of my list segment (using get_emails() custom function, I am setting up my list segment as follows:
$batch = get_emails();
//now create my list segment:
$api->listStaticSegmentAdd(WEDDING_LIST_ID, 'new_wedding_guests');
$api->listStaticSegmentMembersAdd(WEDDING_LIST_ID, 'new_wedding_guests', $batch);
//do I build vars for a campaign?
$options = array (
'list_id' => WEDDING_LIST_ID, //What value id's my list segment?
'subject' => 'Alpha testing.',
'from_email' => 'wedding#juicywatermelon.com',
'from_name' => 'Pam & Kellzo',
'to_name' => $account->name,
);
From here can I use a basic campaign and send it?
$content['text'] = "Some text.";
$content['html'] = get_link($account);
$cid = $api->campaignCreate('regular', $options, $content);
$result = $api->campaignSendNow($cid);
I'm not sure if I'm understanding the api documentation correctly. I also tried 'list_id' => 'new_wedding_guests'; which failed to create a campaign.
Thanks!
I'll assume this is test code and just make the cursory mention of how you probably don't need to be creating a new Static Segment every time. However, your call to add members is not going to work. Per the listStaticSegmentMembersAdd documentation, you should be passing the static segment id, not the name of it. Also note that the docs cross-reference themselves when input params can come from other calls - that parameter there is a good example (it also happens to be returned by listStaticSegmentAdd).
Your options for campaignCreate look like a good start. The documentation for it has examples below - those examples are included in the PHP MCAPI wrapper you likely downloaded. As per above, the list_id you need is the one for the list you used in the listStaticSegment calls (also linked in the documentation).
Now the real key - further down in the campaignCreate docs is the segment_opts parameter - that is how you control segmentation. Follow the link it gives you and you'll find tons of info on the ways you can do segmentation, including using a static_segment.
Hopefully all of that made sense, if not, take a step back and check out these links (and play with segmentation in the app), then it should:
Introduction to MailChimp List Management
How can I send to a segment of my list?
Our Release Info on how Static Segments are used

Categories