Facebook fb:request-form not working - php

I just tried using the example given on developers.facebook.com to open a request form and invite friends, so I changed everything accordingly but nothing happens, do I need to launch it in some way?
<?php
$api_key = '...';
$secret = '...';
require_once 'facebook.php';
// Names and links
$app_name = "...";
$app_url = "http://apps.facebook.com/.../"; // Assumes application is at http://apps.facebook.com/app-url/
$invite_href = "invite.php"; // Rename this as needed
$facebook->require_frame();
$user2 = $facebook->require_login();
if(isset($_POST["ids"])) {
echo "<center>Thank you for inviting ".sizeof($_POST["ids"])." of your friends on <b>".$app_name."</b>.<br><br>\n";
echo "<h2>Click here to return to ".$app_name.".</h2></center>";
} else {
// Retrieve array of friends who've already authorized the app.
$fql = 'SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1='.$user2.') AND is_app_user = 1';
$_friends = $facebook->api_client->fql_query($fql);
// Extract the user ID's returned in the FQL request into a new array.
$friends = array();
if (is_array($_friends) && count($_friends)) {
foreach ($_friends as $friend) {
$friends[] = $friend['uid'];
}
}
// Convert the array of friends into a comma-delimeted string.
$friends = implode(',', $friends);
// Prepare the invitation text that all invited users will receive.
$content =
"<fb:name uid=\"".$user2."\" firstnameonly=\"true\" shownetwork=\"false\"/> has started using ".$app_name." and thought it's so cool even you should try it out!\n".
"<fb:req-choice url=\"".$facebook->get_add_url()."\" label=\"Put ".$app_name." on your profile\"/>";
?>
<fb:request-form
action="<? echo $invite_href; ?>"
method="post"
type="<? echo $app_name; ?>"
content="<? echo htmlentities($content,ENT_COMPAT,'UTF-8'); ?>">
<fb:multi-friend-selector
actiontext="Here are your friends who don't have <? echo $app_name; ?> yet. Invite whoever you want -it's free!"
exclude_ids="<? echo $friends; ?>" />
</fb:request-form>
<?php
}
?>

hello the following code works for me
<fb:serverFbml width="760px">
<script type="text/fbml">
<fb:fbml>
<fb:request-form
action='http://apps.facebook.com/yoursite/'
method='POST'
type='photo fun'
content="Let's fun with facebook
<fb:req-choice url='http://www.yoursite.com' label='Register'/>"
<fb:multi-friend-selector actiontext="Select your friends."></fb:multi-friend-selector>
</fb:request-form>
</fb:fbml>
</script>
</fb:serverFbml>

Related

Generating random ref_id in PHP?

i want to create different ref_id for each users. i tried it with using str_shuffle function. it generates but when i refresh the page it changes. also, it generates the same ref_id for every user. Here are my codes:**
$users = $db->get_results("SELECT * FROM users");
if($users ){
foreach($users as $u){
$str = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPUQRSTUVWXYZ';
$str_r = substr(str_shuffle($str), 0, 30);
$ref_id=$db->query("UPDATE users SET ref_id= '$str_r'") ;
echo "ref_id: $u->ref_id; ";
echo '<br';
}
}
i think i must use while but i didnt get any result. How can i fix this?**
Edit:
i solved the part of "generating different id for each users" but still changes every refreshing. How can i solve that part?
here are the new version of codes above:
$users = $db->get_results("SELECT * FROM users");
if($users){
echo '<div class="container">
<div class="card">
<div class="card-body">';
foreach($users as $u){
$str = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPUQRSTUVWXYZ';
$str_r = substr(str_shuffle($str), 0, 20);
$ref_id=$db->query("UPDATE users SET ref_id= '$str_r' where id='$u->id'") ;
echo "$u->id . users ref_id: $u->ref_id; ";
echo '<br>';
}
}
echo '</div></div></div>';

Inserting fb access token to this code

I had this script from google it was working perfectly, the code was able to retrieve any facebook album from any page
suddenly it stopped working
I did a research on google I found that it needs an access token implementation in the code
but im not able to do it alone any help please
regards
$fb_page_id = "448955931844556";
$json_link = "http://graph.facebook.com/{$fb_page_id}/albums?fields=id,name,description,link,cover_photo,count";
$json = file_get_contents($json_link);
$obj = json_decode($json, true, 512, JSON_BIGINT_AS_STRING);
$album_count = count($obj['data']);
for($x=0; $x<$album_count; $x++){
$id = $obj['data'][$x]['id'];
$name = $obj['data'][$x]['name'];
$description = $obj['data'][$x]['description'];
$link = $obj['data'][$x]['link'];
$cover_photo = $obj['data'][$x]['cover_photo'];
$count = $obj['data'][$x]['count'];
// if you want to exclude an album, just add the name on the if statement
if(
$name!="Profile Pictures" &&
$name!="Cover Photos" &&
$name!="Timeline Photos"
){
$show_pictures_link = "photos.php?album_id={$id}&album_name={$name}";
echo "<div class='col-md-4'>";
echo "<a href='{$show_pictures_link}'>";
echo "<img class='img-responsive' style='height:190px;width:190px;' src='https://graph.facebook.com/{$cover_photo}/picture' alt=''>";
echo "</a>";
echo "<h3>";
echo "<a href='{$show_pictures_link}'>{$name}</a>";
echo "</h3>";
$count_text="Photo";
if($count>1){ $count_text="Photos"; }
echo "<p>";
echo "<div style='color:#888;'>{$count} {$count_text} / <a href='{$link}' target='_blank'>View on Facebook</a></div>";
$description;
echo "</p>";
echo "</div>";
}
}
Add access_token=<your access token> to $json_link
for example:
$fb_access_token = "PUT YOUR ACCESS TOKEN HERE"
$json_link = "http://graph.facebook.com/{$fb_page_id}/albums?access_token={$fb_access_token}&fields=id,name,description,link,cover_photo,count";

Concrete5 User attributes

I figured out how to du this seperatly
Display the user attribute:
<?php
//Create a User object (of the current User)
$u = new User();
//Creat a UserInfo object with the user ID
$ui = UserInfo::getByID($u->getUserID());
//Get the Value of your user Attribute
$value = $ui->getAttribute('name');
//Print it out
echo $value;
?>
Display page owner:
<?php
$ownerID = $cobj->getCollectionUserID();
$uia = UserInfo::getByID($ownerID);
$ownerName = $uia->getUserName();
echo $ownerName
?>
But i cannot figure out how to put them together so it displays the attribute('name'); of the page owner
Can you guys please help
Thanks
After moving a little bit more around with the codes.
i figured out that i just needed to move the
$cobj->getCollectionUserID();
into
$ui = UserInfo::getByID($u->getUserID());
So the finished code:
<?php
//Creat a UserInfo object with the Owner
$ui = UserInfo::getByID($cobj->getCollectionUserID() );
//Get the Value of your user Attribute
$value = $ui->getAttribute('name');
//Print it out
echo $value;
?>

Facebook comments are counted as "shares" and can't be deleted

I am using the facebook comments plugin (http://developers.facebook.com/docs/reference/plugins/comments/ ... not the WordPress plugin) on a WordPress site. Facebook isn't counting the comments as actual "comments", but as "shares". Furthermore, deleting a comment from the facebook 'module' on the WP site, or from my facebook profile doesn't reduce the "shares" count.
Here's the code I'm using
<?php
$source_url = get_permalink();
$url = "http://api.facebook.com/restserver.php?method=links.getStats&urls=".urlencode($source_url);
$xml = file_get_contents($url);
$xml = simplexml_load_string($xml);
echo "Share --- ".$shares = $xml->link_stat->share_count;
echo "<br/>";
echo "Like --- ".$likes = $xml->link_stat->like_count;
echo "<br/>";
echo "Comments ---".$comments = $xml->link_stat->comment_count;
echo "<br/>";
echo "Total --- ".$total = $xml->link_stat->total_count;
echo "<br/>";
echo $max = max($shares,$likes,$comments);
?>
Any insight much appreciated!

Facebook PHP API - sudden problem with users_isAppUser()

we have an iframe facebookapp which worked fine till yesterday. Although we didn't change anything our app suddenly stopped working.
We could identify users_isAppUser() as a problem. The method returns that the user has not added the app though he definitely has installed the app and is logged in. We could delete the try/catch part (see code below), so that the app does not get catched in a redirect loop, but the following methods do not work either:
$this->facebook->api_client->friends_get()
$this->facebook->api_client->friends_getAppUsers()
$this->facebook->api_client->call_method('facebook.users.hasAppPermission', array('ext_perm' => 'publish_stream'))
require_login() does work and we can get the facebook userid of the logged in user.
The weird thing is, that our app worked fine for a couple of weeks till yesterday.
Have there been any secret changes to the API in the last days? Or any other conclusions what the problem could be?
I would appreciate any tips. Thanks in advance!
$this->fbuserid = $this->facebook->require_login();
// check if user has added app, exception gets thrown if the cookie has an invalid session_key i.e. user is not logged in
try {
if(!$this->facebook->api_client->users_isAppUser()) {
$this->facebook->redirect($this->facebook->get_add_url());
}
} catch (exception $ex) {
// clear cookies for application and redirect to login prompt
$this->facebook->set_user(null, null);
$this->facebook->redirect($this->configArray['appcallbackurl']);
}
<?php
// this is sample code taken from the Facebook Developers Site.Thank you to Face book
define('YOUR_APP_ID', '');
define('YOUR_APP_SECRET', '');
function get_facebook_cookie($app_id, $app_secret) {
$args = array();
parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
ksort($args);
$payload = '';
foreach ($args as $key => $value) {
if ($key != 'sig') {
$payload .= $key . '=' . $value;
}
}
if (md5($payload . $app_secret) != $args['sig']) {
return null;
}
return $args;
}
$cookie = get_facebook_cookie(YOUR_APP_ID, YOUR_APP_SECRET);
echo "<pre/>";
/*print_r($_COOKIE);
print_r($cookie);*/
$user = json_decode(file_get_contents('https://graph.facebook.com/me?access_token=' . $cookie['access_token']));
$photo = json_decode(file_get_contents('https://graph.facebook.com/100000439661780/albums?access_token=' . $cookie['access_token']));
echo "<pre/>";
print_r($photo);
?>
<img src="https://graph.facebook.com/ureshpatel5/picture" height="200" width="200" />
<html>
<body>
<?php
$albums = $facebook->api('/me/albums');
print_r($albums);
foreach($albums['data'] as $album)
{
// get all photos for album
$photos = $facebook->api("/{189346844423303_46487}/photos");
foreach($photos['data'] as $photo)
{
echo "<img src='{$photo['source']}' />", "<br />";
}
}
?>
<?php if ($cookie) { ?>
Welcome <?= $user->name ?>
<?php } else { ?>
<fb:login-button></fb:login-button>
<?php } ?>
<?php
echo $photo->source;
?>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({appId: '<?= YOUR_APP_ID ?>', status: true,
cookie: true, xfbml: true});
FB.Event.subscribe('auth.login', function(response) {
window.location.reload();
});
</script>
</body>
</html>

Categories