An open source Facebook app. for a valid cause :)
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.
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:
- Create Facebook PopUp Authentication Window using PHP and javascript
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:
- Graph api & javascript base Facebook Connect tutorial
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:
- Facebook Graph API — getting access tokens
- How to retrieve facebook user’s friendlist
- How to get mutual friends in facebook
And you can find good facebook-related tutorials at this site:
- thinkdiff.net
You can check out https://github.com/brennannovak/codeigniter-facebook-oauth which lets you upload a CodeIgniter setup with a basic example application. It replaces the old php-sdk.
精彩评论