URL for testing my app on facebook - facebook

I'm just starting a new app with the php-sdk. I've done an app a few years ago, but this is the first time with the newer setup dialogs.
The canvas url is pointing to my web server and the app's subdirectory.
Right now this is the only code in my app...just the "hello world" from the php-sdk sample.
<?php
include 'facebook.php';
$facebook = new Facebook(array(
'appId' => 'myappid',
'secret' => 'mysecret',
));
// Get User ID
$user = $facebook->getUser();
?>
Yes, the appid and secret are the actual numbers.
I've waited several minutes to propagate but when going to https://apps.facebook.com/myappsname it just tosses me a 404 error. Is there another URL I should go to when it's in sandbox?

To get https://apps.facebook.com/[APP_NAMESPACE] working, you must specify [APP_NAMESPACE] the App Namespace in the Dev App (https://developers.facebook.com/apps) under Basic settings.

Related

JS and PHP Facebook API

I get the user permission using FB.login JS call. Now when user goes to another page
I'm trying to fetch his fbuid assuming that he does not need to give the permissions again
i.e.
require 'facebook.php';
$facebook = new Facebook(array(
'appId' => YOUR_APP_ID,
'secret' => 'YOUR APP SECRET',
));
$userId = $facebook->getUser();
But I always get 0 instead, What exactly I'm doing wrong?
P.S
I don't want to redirect user to the permission dialog using JS redirect that's why I used JS FB.login
The sessions for JS and PHP must be in the same go. When JS finishes logging in, a cookie is set with the signed request, as long as the same session is reloaded the PHP SDK should be able to recognize it and return a valid user for the getUser() call.

Facebook PHP sdk doesnt set cookie with iframe linking

I am using PHP sdk for Facebook.
require_once 'facebook-sdk/facebook.php';
session_start();
$facebook = new Facebook(array(
'appId' => 'app_id',
'secret' => 'app_secret',
'cookie' => true,
));
$facebook->getUser();
if($user){
// do stuff
}else{
//redirect to app login
}
After this piece of code there is link on my page that points to this same page with a query string.
something like Continue
But when I click this link $user is "0". This happens only şn Safari and IE. When I check cookies set by app doesnt exist in these browsers.
Any ideas?
Since the user id won't change, is it a problem if you send it via GET?
Continue
and then at the top of your script and after getting the $user the way you are doing:
if($_GET['step'] == 2){
$user = $_GET['id'];
}
If you really need to keep the cookies you can add this at the top of your script, it must be the first line.
header('P3P: CP="CAO COR CURa ADMa DEVa OUR IND ONL COM DEM PRE"');
Also you might want to check this questions
Iframe Facebook application and cookies [Internet Explorer]
Session Lost on IE Facebook App iFrame
wich are related to the header solution.

$facebook->getUser() returning 0 using PHP SDK

I have just started with the Facebook application development. I downloaded the PHP SDK from Facebook couple of weeks ago.
Following is the first piece of code which i wrote.
<?php
require 'src/facebook.php';
$app_id = 'My APP ID';
$application_secret = 'My APP Secret';
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $application_secret,
'cookie' => true, // enable optional cookie support
));
$uid = $facebook->getUser();
echo $uid;
?>
But it is always giving me 0 as a result even when i am already login into my facebook account in other tab.
My Canvas URL is pointing to my localhost as i have hosted this app on my local machine only.
I have read almost every post related to this issue but i was not able to solve this issue somehow.. It would be really helpful if anybody could help me in resolving this issue.
Cheers.
Ajay
The code will always return 0 unless you have authorised the app - even if you are logged into facebook elsewhere. Login to your app by going to the URL outputted by $facebook->getLoginUrl();
Then, you will find that $facebook->getUser() will return the correct User ID.

Allowing an internal site URL as well as web-visible site URL in app config

I've read around but I can't find any similar questions so here goes...
I have a facebook application which is configured and working fine, Lets take my website URL to be:
http://adminpanel.its.a.very.long.url.mywebsite.com
This is configured as the 'site URL' in the application config and it works fine.
However, the website is also used on our internal network with a DNS that allows us to use
http://adminpanel/
The problem is that the facebook app wont allow a'redirect_uri' to be
http://adminpanel/
and fails with the following:
API Error Code: 191
API Error Description: The specified URL is not owned by the application
Error Message: Invalid redirect_uri: Given URL is not permitted by the application configuration.
Is it possible to allow both
http://adminpanel.its.a.very.long.url.mywebsite.com
and
http://adminpanel/
Thanks in advance,
Oli
UPDATE: I can't use two apps as I rely the 'Add Page Tab Dialogue' to add my application to various Pages.
What I need is both of these redirects (specified by the 'next' param) to be allowed by facebook.
https://www.facebook.com/dialog/pagetab?app_id=12345678&display=popup&next=http://adminpanel/Success
https://www.facebook.com/dialog/pagetab?app_id=12345678&display=popup&next=http://adminpanel.its.a.very.long.url.mywebsite.com/Success
A common problem, and it's easy to fix. Check out my PHP code below:
if ( strstr( 'adminpanel', $_SERVER['HTTP_HOST'] ) ) {
// this is the localhost settings
$facebook = new Facebook(array(
'appId' => 'xxx',
'secret' => 'xxx',
));
$app_url = 'http://adminpanel/';
$fb_url = 'http://apps.facebook.com/xxx/';
// other settings can go here too
} else {
// this is the main / live site settings
$facebook = new Facebook(array(
'appId' => 'yyy',
'secret' => 'yyy',
));
$app_url = 'http://adminpanel.its.a.very.long.url.mywebsite.com';
$fb_url = 'http://apps.facebook.com/yyy';
// other settings can go here too
}
Problem solved!
The code checks to see which host its running on and loads the correct settings for each. You will need to have two different versions of the App on Facebook. This will let you configure the URLs for each app separately (as in the PHP code above).
If you are using a different language, you can easily do the same thing by detecting the host and putting your config settings in the relevant part of the conditional statement. It will even allow you to configure multiple (i.e. more than 2) environments.

Upload to specific Fan Page Album without user perms

I'm trying to replicate the same functionality as someone else has already achieved on this page here:
http://www.facebook.com/PowerPhotoUploader?sk=app_152884604799537
am not bothered about the forced like fangate part, can do that no probs.
I need to achieve this without requesting any user perms the same way they have
I've got close, but not quite right yet.
Have created a test album on this page: http://www.facebook.com/pages/Demo-Album-Upload/227979503931257?sk=app_153866511376478
The code I have is uploading my specified image, however it is ignoring the album id I input and instead, uploading to an album on my own profile.
Code so far is:
<?php
$app_id = "XXXXXXXXXXX";
$app_secret = "XXXXXXXXXXXX";
require 'facebook.php';
$facebook = new Facebook(array( 'appId' => $app_id, 'secret' => $app_secret, 'cookie' => true, 'fileUpload' => true,));
$signed_request = $facebook->getSignedRequest();
//print_r ($signed_request);
$page_id = $signed_request["page"]["id"];
//Upload To Page Album
$facebook->setFileUploadSupport(true);
$album_id ='59125';
$file_path ='image2.gif';
$args = array('message' => 'Photo Caption');
$args['image'] = '#' . realpath($file_path);
$data = $facebook->api('/'.$album_id.'/photos', 'post', $args);
print_r($data);
?>
Have already read through a lot of forum material, have set the filuploadsupport, set file upload to true, but most of the info I can find so far reuires perms & access token, however sample above has managed to achieve with neither - any thoughts?
Regards Tony
Tony the trick here is that you only need one access token, not a new one for each user. The idea is that the user is not posting to the page, you are posting to the page, so you do not need an access token from the user. However since this is a secure call to Facebook you still need to provide an access token that has the ability to publish to the page.
The simplest route to get an access token that you can use would be to manually give the application the manage_pages and offline_access permissions for your account. Then just grab the access token for for your account and use it for all calls.