Facebook Graph API Group Files - facebook

Facebook offers a new functionality for groups. Now it is possible to post also files within a group. (http://mashable.com/2012/05/10/facebook-groups-3/)
I am trying to query now the files using the Graph API but on the documentation site there are only 4 urls described. "docs", "members", "feed", "picture".
When I read the "feed" path I will not get file postings.
Is there a hidden path? I also found no new permission.
Anyone has any idea?
I have searched for a solution on several internet pages but there are only descriptions on how to read and post photos, which is described in the document.
Is there nobody writing an app where you can upload files to groups?

try this, this might be helpful for you
try {
$facebook->api('/'.$groups[$id].'/feed', 'POST',
array(
'access_token' => $access_token,
'message' => stripslashes(stripslashes($mapp_message)),
'name' => stripslashes($name),
'link' => $link,
'description' => stripslashes(stripslashes($description)),
'picture' => "images/send_imges/".$image
)
);
} catch(FacebookApiException $e) {
echo $e;
}

The Graph API documentation for Groups mentions a way to retrieve the documents from a group. If you click the docs connection in the document, it'll take you to the Graph API Explorer, where you can test your sample queries. So, basically, all you need to do to obtain the document uploaded to a group is perform a request to the following url with a valid Access Token (with no special permission):
https://graph.facebook.com/groupId/docs
Or, if you want to access a specific doc, you need the document_id for that particular doc. So you can simply request the following URL with a valid Access Token:
https://graph.facebook.com/docsId
The instructions on posting a doc and its related permissions have been discussed in this answer. I'm not very sure whether it works or not as I have not tested the method. But I'm pretty sure that you can read the details by making an API call to the urls mentioned above.

Related

Facebook Graph API - Access token for page likes, name and url

I'm trying to update some old PHP code which is supposed to get the name, likes and a link to the given Facebook page. This is the current old code:
$fbsite1 = json_decode(file_get_contents('http://graph.facebook.com/page1'));
$fbsite2 = json_decode(file_get_contents('http://graph.facebook.com/page2'));
$fbsite3 = json_decode(file_get_contents('https://graph.facebook.com/page3'));
for($j=1; $j<=3; $j++){
$data[] = array(
'name' => ${'fbsite'.$j}->name,
'likes' => ${'fbsite'.$j}->likes,
'link' => ${'fbsite'.$j}->link
);
}
The problem is that this method requires an access token, which I'm not quite sure how to get. I've looked at the Facebook API reference, but there seems to be a few different access tokens (different permission etc.). Which one do I need to accomplish this? How do I get it?
If the pages are public, then you only need an app access token.
So create an app in the FB dev section (if you have not done so already), and then include your app access token in those request URLs:
http://graph.facebook.com/page1?access_token=…
FYI, you should consider requesting all that data in one go, instead of making multiple API requests. You can do that using this syntax (for up to 50 ids in one request),
http://graph.facebook.com/?ids=page1,page2,page3&access_token=…
And you will have to explicitly ask for the name, link and likes fields now (otherwise you will get name and id only):
http://graph.facebook.com/?ids=page1,page2,page3&fields=name,likes,link&access_token=…

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

Administrate facebook application via graph api

I was wondering if it is possible to change your site url or canvas url using the graph api. I have admin rights to my application and I can change it via the gui but I would prefer to be changing it via a curl.
Thanks
Here is example:
$properties = array(
"callback_url" => '',
"installable" => 1,
"profile_tab_url" => "",
"tab_default_name" => "",
'tos_url' => '',
'privacy_url' => ''
);
$facebook = new Facebook(array('appId'=>'YOUR_APP_ID','secret' = > '..', ...));
$facebook->api(array(
'method'=>'admin_setAppProperties',
'properties'=>json_encode($properties))
);
Here is a list of the properties you can set: http://developers.facebook.com/docs/appproperties/
There is also admin.getAppProperties more info you can find here: http://developers.facebook.com/docs/reference/rest/admin.getAppProperties/
Using Facebook SDK
You need to use the old REST method admin.SetAppProperties
https://developers.facebook.com/docs/reference/rest/admin.setAppProperties/
At the moment FB has not yet moved that method yet to the OpenGraph but you can still call REST methods via the Graph API (As shown in the console in the page above).
Even then you cannot change the secure_canvas and secure_tab url setting. FB is apparently working on make those settings as part of the API as far as I heard.
You can now change app properties via Graph API. You can make POST request, using the application id in the path, and use the app access token as the access token, and pass in key/value pairs as POST variables for properties you'd like to modify.
https://developers.facebook.com/docs/reference/api/application/ has a list of the application properties that you can modify with the Graph API.

Using 'from' to post a facebook message as App name

I have an Facebook App that is currently posting to a WALL. All the posting are being Titled as MY post. I would like it to be titled by the App. In this documentation, it says there is a 'from' parameter. I've tried to use it a couple of ways and both ways have been unsuccessful. Does anyone have a clue?
https://developers.facebook.com/docs/reference/dialogs/feed/
$attachment = array('message' => $message,
'from' => "<APP_ID>",
//'from' => array('name' => "Sender's Name",'id' => "<APP_ID>"),
}
$me = $this->facebook->api('/me/feed/', 'POST', $attachment);
The from property MUST be a user or a page. You could possibly create a Facebook page with the name of your application and use that.
I've never used the FROM parameter in the Graph API, just on the legacy REST API. And that API parameter was actually actor_id instead of FROM.
Obviously this doesn't solve your problem. To solve your problem, get the access_token for your page from the /me/accounts Graph API end point. When you use this access token, you are identified as the account for which it corresponds, and when you post to /{page_id}/feed with it, it will be posted as the page and in turn be published out to all your users.
<script type="text/javascript">
FB.api("/123123123/feed", "post", {
message: "Test!",
access_token: '184484190795|SDlfkjweifljasdf.3600.123123123.1-2342342|234234234234|XLjsldfjLISJflwieab'
},
function(response)
{
console.log(response);
});
</script>
Thank you all for the suggestions. I finally was able to solve the problem by combining these 2 articles. The basic steps of the first article is still valid. But it is written in the old API. The second article help be get through the step the new REST api couldn't do. Hope this helps.
http://www.emcro.com/blog/2009/01/facebook-infinite-session-keys-no-more/
http://www.alyssapowell.com/2010/10/how-to-generate-an-infinite-session-key-in-facebook/

Create a note with Facebook connect

I am wondering if it is possible to create a note on facebook through my website using facebook connect. I have notes on my website and I essentially want the ability to be able to push them over to the user's facebook account.
I'm not sure - I don't think you actually can.
The reference doesn't have a section on publishing (say, compared to the same page for photos)
However, this is a user_notes extended permission, so perhaps it's possible just not documented? Or it could just be that notes are, indeed, read-only.
As for now, the 'create' part is missing from documentation but after some experimentation it works like this with the graph api based php-sdk:
public function postNote ($title, $content) {
$note_details = array(
'subject'=> $title,
'message'=> $content,
);
$result = $this->facebook->api('/me/notes', 'post', $note_details);
}
publish_stream permission is required