I'm "translating" a simple app I made with PHP to Python in order to use it in Google App Engine.
In PHP I have the session check and the redirection with this code:
$fbuser = null;
$fb = null;
//Start Facebook
$fb = new Facebook(array(
'appId' => $appId,
'secret' => $secret,
'cookie' => true,));
$session = $fb->getSession();
if ($session) {
try {
$fbuser = $fb->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
}
}
if (!$fbuser) {
$loginUrl = $fb->getLoginUrl(array('canvas' => 1, 'fbconnect' => 0,
'req_perms' => 'publish_stream, offline_access, user_birthday, user_location, email',
'next' => $baseUrl,
'cancel_url' => $baseUrl ));
echo "<script type=\"text/javascript\">\ntop.location.href = \"$loginUrl\";\n</script>";
exit;
}
I've seen the Python-SDK for Facebook but it's very poor and hasn't all the useful method as PHP-SDK!
Can you help me translate this code to Python?
I think this example from the SDK git repository will give you a hint.
Related
I'm building facebook app. I need to get some permissions. I use php sdk.
Everything works fine, but the problem is that LOGIN URL opens in popup mode and some browsers doesn't allow that action.
Can you tell what can I do in this case?
<?php
require 'src/facebook.php';
$config = array(
'appId' => '123456789',
'secret' => '123456789',
'fileUpload' => true,
'allowSignedRequest' => false
);
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
if($user_id) {
try {
include "some.php";
$user_profile = $facebook->api('/me','GET');
} catch(FacebookApiException $e) {
$login_url = $facebook->getLoginUrl(array( 'scope' => 'photo_upload', 'scope' => 'user_likes', ));
header ("Location: $login_url");
error_log($e->getType());
error_log($e->getMessage());
}
} else {
$login_url = $facebook->getLoginUrl(array( 'scope' => 'photo_upload', 'scope' => 'user_likes', ));
header ("Location: $login_url");
}
?>
I want to use PHP to send message to my Facebook friends. I found some code but it just lets me log in. Could anyone help me?
<?php
require 'facebook.php';
$facebook = new Facebook(array(
'appId' => 'XXXXX',
'secret' => 'XXXXX',
'cookie' => true,
));
$session=$facebook->getUser();;
if ($session) {
$logoutUrl = $facebook->getLogoutUrl();
$access_token = $facebook->getAccessToken();
try {
$result = $facebook->api(
'me/feed',
'post',
array('access_token' => $access_token , 'message' => 'test')
);
} catch (FacebookApiException $e) {
error_log($e);
}
}
1) Did you provided the correct permissions to the app?
$login_url = $facebook->getLoginUrl( array(
'scope' => 'publish_stream'
));
2) Check this answer: Update facebook status using php and this: Facebook PHP SDK , Post to another users wall whats wrong?
3) it's /me/feed, not me/feed:
$result = $facebook->api(
'/me/feed',
'post',
array('access_token' => $access_token , 'message' => 'test')
);
I get from facebook some code to auto sharing , so i need to edit my code to get , auto sharing several times , not only 1 time....i need a help in how to make that issue , i let for you my code:
//-- Facebook API --//
require_once 'php-sdk/facebook.php';
//-- App Information --//
$app_id = 'zzzzzzzzz';
$app_secret = 'xxxxxxxxxxxxxxxxxxxxx';
$pageId= 'me';
// Create Facebook Instance
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
//-- To Facebook (Notice we ask for offline access) --//
if (empty($_REQUEST))
{
$loginUrl = $facebook->getLoginUrl(array(
'canvas' => 1,
'fbconnect' => 0,
'scope' => 'offline_access,publish_stream'
));
header('Location:'.$loginUrl );
}
//-- From Facebook --//
else
{
$user = $facebook->getUser();
if($user)
{
$access_token = $facebook->getAccessToken();
$req = array(
'access_token' => $access_token,
'message' => 'Jeremy Gibbs is a handsome lad!');
//-- Send post to Facebook --//
$res = $facebook->api('/'.$pageId.'/feed', 'POST', $req);
header("location: http://facebook.com/".$pageId."");
}
}
so can u tell me how ?
You can user cron jobs on your server OR use http://twitterfeed.com/
i get an error while trying to automatically post a link with Facebook Graph API
My php code
<?
$config = array();
$config['appId'] = '3545XXXXXXX6207';
$config['secret'] = '60068XXXXXXXXXXXe45a426';
$facebook = new Facebook($config);
$retour_login = json_decode(stripslashes($_GET['session']), true);
$uid = $retour_login['uid'];
$access_token = $retour_login['access_token'];
$me = null;
if ($session) {
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
}
}
if(!isset($_GET['session'])) { // Asking permissions
$params = array(
'locale' => 'fr_FR',
'display' => 'popup',
'req_perms' => 'email,user_about_me,user_birthday,user_location',
'ext_perms' => 'publish_stream,share_item,manage_pages'
);
header("Location: ".$facebook->getLoginUrl($params));
}
$args = array(
'message' => "XXXX",
'link' => 'XXXX',
'name' => 'XXXX',
'picture' => 'XXXX',
"caption"=> "lien.com",
"type"=> "link");
$post_id = $facebook->api("/me/links", "post", $args); // execute this to automatically post on FB
?>
I get this error : OAuthException: (#282) Requires extended permission: share_item thrown
Any ideas ?
Thanks!
What are 'req_perms' and 'ext_perms' there? the permissions should be in a 'scope' parameter according to the documentation - https://developers.facebook.com/docs/reference/dialogs/oauth/ and https://developers.facebook.com/docs/authentication/
Check you're not working from an outdated example or tutorial - always check the official documentation first
I am in the process of devloping a facebook canvas application in php and FBML, and am having issues when it comes to setting up authorization for the application. I basicly do not kno how to go about it, or what the best method is.
I have been searching around on the internet most of the day but either stummble on old API things, or i dont know how to implement what they are explaining.
Here is what i have:
$facebook = new Facebook(array(
'appId' => '*snip*',
'secret' => '*snip*',
'cookie' => true,));
$session = $facebook->getSession();
$fbme = null;
if ($session) {
try {
$uid = $facebook->getUser();
$fbme = $facebook->api('/me');
} catch (FacebookApiException $e) {
d($e);
}
}
if (!$fbme) {
$loginUrl = $facebook->getLoginUrl(array(
'canvas' => 1,
'fbconnect' => 0,
'req_perms' => "publish_stream,user_birthday,friends_birthday,user_events,user_hometown,friends_hometown,user_location,friends_location,offline_access,"
));;
}
if (isset($loginUrl)) {
echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
exit;
}
But that does nothing, and if i try with changing the headers instead of using script block, i get:
The URL ... is not valid
Am i going about this all wrong?
Thanks in advance for any help.
Andy
My common include has the following for authenticating:
$facebook = new Facebook(array(
'appId' => $ini['appid'],
'secret' => $ini['appsecret'],
'cookie' => true,
));
$session = $facebook->getSession();
$fbme = null;
if ($session) {
try {
$fbme = $facebook->api('/me');
}
catch (FacebookApiException $e) {
error_log($e);
}
}
// new login check
if (!$fbme) {
$loginUrl = $facebook->getLoginUrl(array(
'canvas' => 1,
'fbconnect' => 0,
'req_perms' => 'email',
'next' => FB_APP_URL,
'cancel_url' => FB_APP_URL,
));
echo '<fb:redirect url="' . $loginUrl . '" />';
}
That basically shows a message prompting the using the either add the application or leave; if they are already authenticated then just proceeds with what's beyong the if (!$fbme) block.