Facebook Graph API search posts with picture - facebook

Im using the Facebook php API in order to search public posts with a specific hashtag in it.
Here is my code:
<?php
require 'facebookauth/facebook.php';
$facebook = new Facebook(array(
'appId' => 'myappid',
'secret' => 'myappsecret',
));
$query = urlencode('hashtag');
$type = 'post';
$ret = $facebook->api('/search?q='.$query.'&type='.$type.'&limit=10000');
echo json_encode($ret);
?>
My problem is that the above code doesn't return the posts that have an image attached.
I am posting from my profile a public post with the hashtag that im searching and if its only text i see it normally in my query results, but if i try to attach an image an write the same text it isnt returning me my post.
Can anybody help?thanx!

I also faced the same problem, it is because a post with an attached picture is no longer considered as post but as a photo contained in the timeline pictures album which one is not searchable through the search api. Can't wait for real hashtag search reachable through the api.

Related

Facebook "Boost Post" through API?

I've been crawling through the documentation and found out that it IS possible to achieve a "Boost Post" functionality through the Facebook Ad APIs. However, I have had some trouble finding what exactly the Boost Post does? i.e. Which part of the API corresponds the "Boost Post" functionality of the Facebook UI?
https://developers.facebook.com/docs/marketing-api/adcreative/v2.4
This page outlines several types of ads. What are the types Facebook "Boost Post" button makes? Or is this wrong part of the API?
See the example for creating an ad_campaign here: https://developers.facebook.com/docs/marketing-api/reference/ad-campaign#Creating
The object (page post in this case) you're trying to promote is set as the promoted object.
You can also set the lifetime or daily budget of the ad at the campaign level.
From the Facebook docs,
For creating an ad from Page post ( boosting a post ), you will first need to create the creative for that ad from the post.
See the doc page on how to create ad adcreatives. Search for Create an ad from an existing page post
use FacebookAds\Object\AdCreative;
use FacebookAds\Object\Fields\AdCreativeFields;
$creative = new AdCreative(null, 'act_<AD_ACCOUNT_ID>');
$creative->setData(array(
AdCreativeFields::NAME => 'Sample Promoted Post',
AdCreativeFields::OBJECT_STORY_ID => <POST_ID>,
));
$creative->create();
After that you will need to create an ad using that creative ad.
Creating ads from API with creative id
require __DIR__ . '/vendor/autoload.php';
use FacebookAds\Object\AdAccount;
use FacebookAds\Object\Ad;
use FacebookAds\Api;
use FacebookAds\Logger\CurlLogger;
$access_token = '<ACCESS_TOKEN>';
$app_secret = '<APP_SECRET>';
$app_id = '<APP_ID>';
$id = '<AD_ACCOUNT_ID>';
$api = Api::init($app_id, $app_secret, $access_token);
$api->setLogger(new CurlLogger());
$fields = array(
);
$params = array(
'name' => 'My Ad',
'adset_id' => '<adSetID>',
'creative' => array('creative_id' => '<adCreativeID>'),
'status' => 'PAUSED',
);
echo json_encode((new AdAccount($id))->createAd(
$fields,
$params
)->exportAllData(), JSON_PRETTY_PRINT);
The examples on the above are using Facebook PHP Business SDK, but you can make the calls using the Facebook PHP Graph SDK with the same parameters.
See the respective SDK files for finding the exact API parameters name.
For example : the Business SDK parameter
AdCreativeFields::OBJECT_STORY_ID is object_story_id as the API parameter.
Hope that helps
I think what you want is a "Page Post Ad". My understanding is that this is really what "Boosting a Post" creates, but in a streamlined way. Coming in through the API, there is no such streamline, so the term "Boost" doesn't get used, but there is still some pretty good documentation.
I'd start with the second paragraph of this section:
https://developers.facebook.com/docs/marketing-api/buying-api/ad-units#creative

How to get latest 10 post feeds from facebook?

I know this question has been addressed many times but I am still facing problems, So I wanted to ask here if anyone can help.
I used facebook SDK to get the latest posts, here is the code below:
require "facebook.php";
$facebook = new Facebook(array(
'appId' => YOUR_APP_ID,
'secret' => YOUR_APP_SECRET,
));
$pageFeed = $facebook->api(THE_PAGE_ID . '/feed');
Then I print_r the results but I am getting feeds like [story] which contains information like I have added someone as a friend or I have post somewhere, but there is also an attribute [message] which contains my reply on some post.
Now 1st thing I am getting only 4 feeds where is I want 10 feeds.
2nd thing is what information I shall extract to show on my website as latest post feeds (story, message or some other attribute)? Keeping in mind that I do not have both of these fields in every array.
If there is something I may not have mentioned here kindly do ask.
Thanks.
You have to use posts instead of feed because feed includes user postings too.
You can test it in Graph Explorer with <your page id>/posts?limit=10 to get last 10 posts of your fanpage.
So your code should look like
require "facebook.php";
$facebook = new Facebook(array(
'appId' => YOUR_APP_ID,
'secret' => YOUR_APP_SECRET,
));
$pageFeed = $facebook->api(THE_PAGE_ID . '/posts?limit=10');

How to upload custom app image (tab_image) for Timeline Page tabs via API?

Facebook released the new Timeline for Pages today. Apps installed to pages as "tabs" now appear above the timeline with a 111px x 74px size thumbnail "app image". You can customize this on a per-page level (just like the custom tab name) if you navigate the Facebook Page admin interface.
You can update the tab's "custom name" via the Open Graph API, but they do not appear to have updated their API docs to show how to upload a custom tab_image (assuming they will). Is it possible now but undocumented? Has anyone figured out how to do this yet?
Updated 2016:
With the latest Open Graph 2.5 API tabs endpoint and PHP SDK 5, the code should look like this:
<?php
$fb = new Facebook\Facebook([/* . . . */]);
$response = $fb->post(
'/{page-id}/tabs',
[
'custom_name'=>'My Custom Tab',
'custom_image_url'=>'http://publicly.accessible/image.jpg',
'app_id'=>'{app-id}',
],
'{page-access-token}',
);
Original 2012 post:
I figured it out, it's just like uploading an image. The field is called "custom_image". Presumably they will update the documentation soon. It's nice they enabled this API hook so quickly with the new release!
Here's how to do it with the Facebook PHP SDK:
<?php
$page_access_token = 'XXXXXXX'; // you'll need the manage_pages permission to get this
$facebook = new Facebook(array(
'appId' => 'YOUR_APP_ID',
'secret' => 'YOUR_APP_SECRET',
'fileUpload' => true, // enables CURL # file uploads
));
$facebook->api(
'/PAGE_ID/tabs/TAB_NAME', // looks like "app_xxxx" where xxxx = APP_ID
'POST' // post to update
array(
'custom_image' => '#' . realpath('path/to/my/file.jpg'),
'custom_name' => 'My App', // give it a custom name if you want too
'access_token' => $page_access_token // access token for the page
)
);
Cheers
As you said Timeline for Pages is just announced and it's too soon to say it'll be possible via API. Currently it's not possible even in settings of your App in Developer Application.
This information is simply not yet documented in help center or Graph API documentation.
It's also way soon to say someone have discovered if such functionality exists...
We all should wait a bit and probably file bugs which may get some response from officials confirming, rejecting or adding this to wish list.

Upload to specific Fan Page Album without user perms

I'm trying to replicate the same functionality as someone else has already achieved on this page here:
http://www.facebook.com/PowerPhotoUploader?sk=app_152884604799537
am not bothered about the forced like fangate part, can do that no probs.
I need to achieve this without requesting any user perms the same way they have
I've got close, but not quite right yet.
Have created a test album on this page: http://www.facebook.com/pages/Demo-Album-Upload/227979503931257?sk=app_153866511376478
The code I have is uploading my specified image, however it is ignoring the album id I input and instead, uploading to an album on my own profile.
Code so far is:
<?php
$app_id = "XXXXXXXXXXX";
$app_secret = "XXXXXXXXXXXX";
require 'facebook.php';
$facebook = new Facebook(array( 'appId' => $app_id, 'secret' => $app_secret, 'cookie' => true, 'fileUpload' => true,));
$signed_request = $facebook->getSignedRequest();
//print_r ($signed_request);
$page_id = $signed_request["page"]["id"];
//Upload To Page Album
$facebook->setFileUploadSupport(true);
$album_id ='59125';
$file_path ='image2.gif';
$args = array('message' => 'Photo Caption');
$args['image'] = '#' . realpath($file_path);
$data = $facebook->api('/'.$album_id.'/photos', 'post', $args);
print_r($data);
?>
Have already read through a lot of forum material, have set the filuploadsupport, set file upload to true, but most of the info I can find so far reuires perms & access token, however sample above has managed to achieve with neither - any thoughts?
Regards Tony
Tony the trick here is that you only need one access token, not a new one for each user. The idea is that the user is not posting to the page, you are posting to the page, so you do not need an access token from the user. However since this is a secure call to Facebook you still need to provide an access token that has the ability to publish to the page.
The simplest route to get an access token that you can use would be to manually give the application the manage_pages and offline_access permissions for your account. Then just grab the access token for for your account and use it for all calls.

Facebook API to retrieve wall feed

I've never done any facebook development and am working on a project which I only require to pull out wall stream from a certain user. Is there such an API I could use for this purpose?
Facebook exposes a generic API. You can write your own methods of accessing it, or you can use Facebook's libraries (if your preferred language is available). Check out the following link to get started:
Getting started
Well, if you're happy with JSON, just using the graph API is a good start.
e.g. https://graph.facebook.com/starbucks/feed
Not too hard to pull that down with Python and put the data in a table...
Though this is an old post, still i am putting in my reply. This might be helpful.
I am using php sdk and here is code for getting the users wall posts (includes posts by other users as well)
$facebook = new Facebook(array(
'appId' => '101874630007036',
'secret' => '2090c8d645ae93e7cacee2217cd3dc0c',
));
$user = $facebook->getUser();
// Login or logout url will be needed depending on current user state.
if ($user)
{
$logoutUrl = $facebook->getLogoutUrl();
}
else
{
$params = array('scope' => 'read_stream');
$loginUrl = $facebook->getLoginUrl($params);
}
if ($user)
{
$comments = $facebook->api('/me/home');
}
here $comments contains the wall post json data.