views:

128

answers:

1

Hello all, I own a couple of pages against Child abuse and now I'm developing a Facebook application for fighting against Child Abuse.

I'm somewhat a newbie, and I found many wonderful resources on the net, however, I don't seem to find what I really want.

I know to build a basic app that accesses a user's basic information(using fb_sig_user). However, I need the code to publish static content to my users' wall, request permissions for the same, (would be nice if it publishes each time they interact with my page).

It would also be nice if the app can post to the user's friends too..but its not a must.

Can someone help me? I have these files with me (its an FBML app,btw) and I'm stuck :

tab.php

<?php
 if (isset($_REQUEST['name'])){
$uidc2 = $_REQUEST['fb_sig_user'];
echo $uidc2;

?>

<div id="update"></div>
<form action="" id="frm_test" method="post" onsubmit="return false;">
 <input type="hidden" name="name" size="50" />
 <input name="name" type="button" clickrewriteurl='http://somewebsite.com/fb/tab.php' clickrewriteform='frm_test' clickrewriteid='update' value="submit"/>
</form>

index.php

<?php

require 'facebook.php';

$app_id = 'xyzzy';
$application_secret = 'abc';

$facebook = new Facebook(array(
  'appId'  => $app_id,
  'secret' => $application_secret,
  'cookie' => true, // enable optional cookie support
));

if ($facebook->getSession()) {
  echo '<a href="' . $facebook->getLogoutUrl() . '">Logout</a>';
  $user = $facebook->getUser();
} else {
  echo '<a href="' . $facebook->getLoginUrl() . '">Login</a>';
}

?>

Any help a this point is really much appreciated. Thank you.

+2  A: 

You can use the stream.publish method to publish stream to users of your app. If you want to post to users' wall even if they are not logged in, you need to ask them for the publish_stream extended permission first.

Update:

Getting Permissions

To get permissions, have a look at:

Alternatively,

In your main config or header 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.

To Publish Steam

There is another javascript sdk method named FB.ui. Using the code you can prompt user for stream publish or share your page. Checkout streamPublish() and share() methods defination in my demo’s source code .

Have a look at this tutorial for more info:

Or You can use this function to publish the steam:

function publish() {

    var attachment = {
        'name': 'App Name',
        'href': 'http://apps.facebook.com/someapp/', 'caption': '{*actor*} perfomed an action!!',
        'description': 'The description goes here',
        "media": [{ "type": "image", "src": "http://www.example.net/images/logo.png", "href": "http://apps.facebook.com/someapp/"}]
    };

    var action_links = [{ 'text': 'World Winner 2010', 'href': 'http://apps.facebook.com/world_winner/'}];

    Facebook.streamPublish('', attachment, action_links);
}

Change the settings in above function as per your requirements and call it like this when you need to publish the stream:

publish();

More Resources:

And you can find good facebook-related tutorials at this site:

Sarfraz
Thanks :) but how do I include it in the above code?
imaginonic
@imaginonic: It depends when you want to publish the streams. Usually it is sent upon some action like clicking on a link or when accessing the app. It is up to you when you want to publish it.
Sarfraz
Sorry to trouble you Sarfraz..but..I would be grateful if you can let me know how I can1) request for "publish_stream"2) automatically publish to a user's wall after getting the permission for the sameThank you
imaginonic
@imaginonic: I will be right back after an hour, got to go for some urgent task. Will come back and answer that if there are no more answers :)
Sarfraz
Thank you, will be waiting :)
imaginonic
@imaginonic: For some light reading, whilst @Sarfraz is busy, check out the Facebook Authentication Page - http://developers.facebook.com/docs/authentication/ - specifically the section titled "Requesting Extended Permissions", as there is something there about "publish_stream" access.
Lucanos
@imaginonic: See my updated answer please.
Sarfraz
@Lucanos and @Sarfraz - Thank you very much guys, you just made my day :)
imaginonic
A special thanks goes to Safraz for his wonderful help, thank you very much, you rock :)
imaginonic
@imaginonic: You are welcome :)
Sarfraz