PHP SDK: Post to FB application's wall as the app itself - facebook

There are a lot of questions on SO about this, but not exactly what I am looking for.
In my case, users can log in through Facebook/Twitter/other. And they can upload an image.
Once they upload an image, two things will happen. The FB user's status is updated with an attachment to the link. And on the FB App's wall, a status update is also posted but by the application itself and not by the user. I am having trouble with this last part. So the user does not have to be logged in through Facebook for this latter to occur.
My code:
$facebook = new Facebook($config);
$attachment = array(
'message' => 'A user just posted a new item',
'name' => $tag,
'caption' => $desc,
'link' => WEBURL,
'description' => '',
'picture' => $img,
'actions' => array(array('name' => 'Go to item',
'link' => WEBURL))
);
$facebook->api('/'.PAGEID.'/feed', 'POST', $attachment);

An application's wall behaves exactly like a page's wall or a user's wall. Lookup the documentation for those.

Related

Trying to post to facebook page with app but get "The user hasn't authorized the application to perform this action"

I am trying to write a script that will post an update to a facebook page timeline. I created an app and created a key for the app. I am using the code below:
require_once HOME_PATH . '/include/facebook/facebook.php';
$facebook = new Facebook(array(
'appId' => FACEBOOK_APP_ID,
'secret' => FACEBOOK_APP_SECRET,
'cookie' => true,
'scope' => 'publish_stream',
));
$user_id = $facebook->getUser();
$access_token = $facebook->getAccessToken();
$attachment = array(
'access_token' => $access_token,
'message' => 'this is my message',
'name' => 'name',
'link' => ROOT_URL . $blog_data['url'] . '.htm',
'caption' => $blog_data['title'],
'description' => $blog_data['title'],
);
if ($image = get_first_image($blog_data['body'])) {
$attachment['picture'] = $image;
}
$facebook->api(FACEBOOK_BLOG_PAGE . '/feed', 'post', $attachment);
i think this key is connected to the app and not to my user, so it sounds like i would have to grant the permission within facebook, but i have seen some other posts telling me that i need to do this in code. The examples aren't very clear.
I know similar questions have been asked but i haven't seen any clear answers yet. Can anyone please clarify this?
If you want to get user_id by this piece of code: $user_id = $facebook->getUser();
The first thing you need, is to login an user through a URL returned by $facebook->getLoginUrl(array('scope' => array('perm', 'perm2'))).
Also, notice, where I put permissions, which I require. Not into the Facebook class constructor, but into the method getLoginUrl.
And lastly, for posting into a page, you need publish_actions permission (not publish_stream).

Cannot post link to fb via app

If I post a link, it shows up ad posted by me as user. If I post a message, it shows up as posted by the page itself. Why is that? I need the link to show up as posted by the page, not me. The page is mine.
$attachment = array(
'access_token' => 'page-token-here',
'image' => $code->image_urls,
'name' => $code->title,
'link' => $short_url,
);
$page_id="page-id-here";
$res = $facebook->api('/'.$page_id.'/feed','POST',$attachment);

Facebook publication from app to page wall invisible to others

I have a big problem, I try to publish a post from an Facebook app to a Facebook page wall.
I used this function to do so :
function Post_facebook($message){
include_once('php-sdk/facebook.php');
$app_config = array(
'appId' => '*********',
'secret' => '************');
$page_config = array(
'access_token' => '********',
'page_id' => '*********');
$facebook = new Facebook($app_config);
$params = array(
'access_token' => $page_config['access_token'],
'message' => $message);
$post_id = $facebook->api('/'.$page_config['page_id'].'/feed','post',$params);
}
Everything seems to be ok, but only I can see the posts.
When I'm on the wall everything seems normal, I see posts from the app. But if someone else goes on the wall, he won't be able to. Publication are set to 'Public' on privacy settings so I can't see why it's not working.
If I go to post URL (https://www.facebook.com/*****/posts/*****) from another account it says : page doesn't exist....
You need to disable sandbox-mode from your Facebook app's settings

Send notification or post on wall

i have been going crazy and cant figure out how to make a script for my application that would allow the user to select a friend and send them a notification or post on their wall from my application.
I just need to notify their friend that they have been challenged to play a flash games, just a simple text with a link, i dont need anything fancy :D
Here is what i tried and it doesnt work :( no idea why.
$message = 'Watch this video!';
$attachment = array( 'name' => 'ninja cat', 'href' => 'http://www.youtube.com/watch?v=muLIPWjks_M', 'caption' => '{*actor*} uploaded a video to www.youtube.com', 'description' => 'a sneaky cat', 'properties' => array('category' => array( 'text' => 'pets', 'href' => 'http://www.youtube.com/browse?s=mp&t=t&c=15'), 'ratings' => '5 stars'), 'media' => array(array('type' => 'flash', 'swfsrc' => 'http://www.youtube.com/v/fzzjgBAaWZw&hl=en&fs=1', 'imgsrc' => 'http://img.youtube.com/vi/muLIPWjks_M/default.jpg?h=100&w=200&sigh=__wsYqEz4uZUOvBIb8g-wljxpfc3Q=', 'width' => '100', 'height' => '80', 'expanded_width' => '160', 'expanded_height' => '120')));
$action_links = array( array('text' => 'Upload a video', 'href' => 'http://www.youtube.com/my_videos_upload'));
$target_id = $user;
$facebook->api_client->stream_publish($message, $attachment, $action_links, $target_id);
UPDATE:
appinclude.php
$facebook->redirect('https://graph.facebook.com/oauth/authorize?client_id=132611566776827&redirect_uri=https://apps.facebook.com/gamesorbiter/&scope=publish_stream');
Error i get:
{
"error": {
"type": "OAuthException",
"message": "Invalid redirect_uri: The Facebook Connect cross-domain receiver URL (https://apps.facebook.com/gamesorbiter/) must be in the same domain or be in a subdomain of an application's base domain (gamesorbiter.com). You can configure the base domain in the application's settings."
}
}
Without the extra "s"(http) i get this error:
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
Please if you could post an example.
Also do i need extended permission to do that or if the user sends the message i dont need that ?
Thank You
Also do i need extended permission to
do that or if the user sends the
message i dont that ?
Yes, you need the offline_access and publish_stream extended permission from the users.
Update:
In your appinclude.php file, put code like this:
$facebook = new Facebook($appapikey, $appsecret);
$user = $facebook->require_login();
$facebook->redirect('https://graph.facebook.com/oauth/authorize?
client_id=[YOUR APP ID]&
redirect_uri=[YOUR APP URL]&
scope=publish_stream, offline_access');
Replace [YOUR APP ID] with application id that you can see from application settings where you created the site in Facebook Developers section. Also replace the [YOUR APP URL] with your app url.

How to include html in stream.Publish

I'm using the old Rest API (and old Javascript SDK) to develop an iframe application inside facebook.
However I would like to have the wall posts (calling stream.Publish) to include new lines and having people's names with links to their profiles. However every time I include html content, FB strips it.. but I know it can be done, because some apps do it, for example:
http://img.skitch.com/20100702-jhqradpi3td4d53sdb3qin92sb.png
Cheers,
Ze
You cannot have arbitrary HTML in a wall post. If it looks like HTML, Facebook will strip it. The only other alteration Facebook will do I believe is convert text that looks like links into links (so if you have http://www.google.com somewhere in the message, Facebook will automatically turn it into a link).
However Facebook does provide basic facilities for including basic things like a picture, caption, description, link, etc through stream.publish by passing in additional parameters. This is an example for including a few of these things from Facebook's documentation (http://wiki.developers.facebook.com/index.php/Stream.publish):
$message = 'Check out this cute pic.';
$attachment = array(
'name' => 'i\'m bursting with joy',
'href' => 'http://icanhascheezburger.com/2009/04/22/funny-pictures-bursting-with-joy/',
'caption' => '{*actor*} rated the lolcat 5 stars',
'description' => 'a funny looking cat',
'properties' => array('category' => array(
'text' => 'humor',
'href' => 'http://www.icanhascheezburger.com/category/humor'),
'ratings' => '5 stars'),
'media' => array(array('type' => 'image',
'src' => 'http://icanhascheezburger.files.wordpress.com/2009/03/funny-pictures-your-cat-is-bursting-with-joy1.jpg',
'href' => 'http://icanhascheezburger.com/2009/04/22/funny-pictures-bursting-with-joy/')),
'latitude' => '41.4', //Let's add some custom metadata in the form of key/value pairs
'longitude' => '2.19');
$action_links = array(
array('text' => 'Recaption this',
'href' => 'http://mine.icanhascheezburger.com/default.aspx?tiid=1192742&recap=1#step2'));
$attachment = json_encode($attachment);
$action_links = json_encode($action_links);
$facebook->api_client->stream_publish($message, $attachment, $action_links);
Check this out for more info on what attachments you can include.