Error in facebook app - facebook

I am using javascript sdk to update status in facebook. This is my code
window.fbAsyncInit = function() {
FB.init({
appId : 'id', // App ID
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
// Additional initialization code heres
FB.login(function(response) {
if (response.authResponse) {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Good to see you, ' + response.name + '.');
});
} else {
console.log('User cancelled login or did not fully authorize.')
}
});
};
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "http://connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
</script>
but i am getting An error occurred message while opening this page.please give a solution to solve this.Or any one else can share the app id which is working fine

Related

Facebook app is just posting content on my wall?

I have created a Facebook app which will share a link to users wall
but the issue is the link is posted on my wall but not on any other user's wall
i have put on live link Link to post on wall app
the code of app that will post on users wall is given below is there anything i need to approve it from the facebook or is there any mistake in my code please i need a real help any one could do ?
waiting for your kind response i am new to the Facebook API
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId: '763390233734216', // App ID from the app dashboard
//channelUrl : '//local.facebook-test/channel.html', // Channel file for x-domain comms
status: true, // Check Facebook Login status
xfbml: true, // Look for social plugins on the page
oauth: true // Enable oauth authentication
});
// Additional initialization code such as adding Event Listeners goes here
FB.login(function(response) {
if (response.authResponse) {
console.log(response.authResponse.accessToken);
var params = {};
params['name'] = 'Seasons Canola';
params['description'] = 'Description';
params['link'] = 'http://vimeo.com/99708842';
FB.api('/me/feed', 'post', params, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
} else {
alert('Not logged in');
}
}, {
scope: 'public_profile,email,publish_actions'
});
};
// Load the SDK asynchronously
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {
return;
}
js = d.createElement(s);
js.id = id;
js.src = "//connect.facebook.net/en_US/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>

Facebook app: permission not updating

I am making a facebook app for which i need permissions other than the basic permission. I have tried using scope as well as changing in the app settings, still I get only the basic permissions and no more other permissions. Below is the code :
<html>
<head></head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'xxxxxxxxxxxx',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.Event.subscribe('auth.authResponseChange', function(response) {
if (response.status === 'connected') {
testAPI();
} else if (response.status === 'not_authorized') {
FB.login(function(response) {
// handle the response
}, {scope:'user_photos,user_friends,friends_photos,user_status,publish_stream,user_photo_video_tags'});
} else {
FB.login(function(response) {
// handle the response
}, {scope:'user_photos,user_friends,friends_photos,user_status,publish_stream,user_photo_video_tags'});
}
});
};
// Load the SDK asynchronously
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Good to see you, ' + response.name + '.');
});
}
});
</script>
<fb:login-button show-faces="true" width="200" max-rows="1"></fb:login-button>
</body>
</html>
I understand that it takes some time for app permissions to propagate, but I have waited for hours. Any hint on whats going wrong here?
Thanks.
Not sure why your code is not working and I am yet to try running it on my machine by I am posting a working code here. Please try using this code after following steps mentioned below
Create a new app on facebook.
In Permissions tab, select the user permissions that you want from user.
In code mentioned below, input your app id and try running it.
Code below is taken from http://hayageek.com/examples/oauth/facebook/oauth-javascript/index.php and is basic implementation of Javascript SDK.
<html>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'XXXX', // App ID
channelUrl : 'http://192.168.1.146/facebook/index.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.Event.subscribe('auth.authResponseChange', function(response)
{
if (response.status === 'connected')
{
document.getElementById("message").innerHTML += "<br>Connected to Facebook";
//SUCCESS
}
else if (response.status === 'not_authorized')
{
document.getElementById("message").innerHTML += "<br>Failed to Connect";
//FAILED
} else
{
document.getElementById("message").innerHTML += "<br>Logged Out";
//UNKNOWN ERROR
}
});
};
function Login()
{
FB.login(function(response) {
if (response.authResponse)
{
getUserInfo();
} else
{
console.log('User cancelled login or did not fully authorize.');
}
},{scope: 'user_photos'});
}
function getUserInfo() {
FB.api('/me', function(response) {
var str="<b>Name</b> : "+response.name+"<br>";
str +="<b>Link: </b>"+response.link+"<br>";
str +="<b>Username:</b> "+response.username+"<br>";
str +="<b>id: </b>"+response.id+"<br>";
str +="<b>Email:</b> "+response.email+"<br>";
str +="<input type='button' value='Get Photo' onclick='getPhoto();'/>";
str +="<input type='button' value='Logout' onclick='Logout();'/>";
document.getElementById("status").innerHTML=str;
});
}
function getPhoto()
{
FB.api('/me/picture?type=normal', function(response) {
var str="<br/><b>Pic</b> : <img src='"+response.data.url+"'/>";
document.getElementById("status").innerHTML+=str;
});
}
function Logout()
{
FB.logout(function(){document.location.reload();});
}
// Load the SDK asynchronously
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
</script>
</div>
</body>
</html>
Update: Hope this solves your problem, I will have a look at your tonight and explain what is going wrong with it.

how to get email address in face book api

I already use this code,i get user name but i can't get email address please some example how to get email address in face api .but many user give some example it does n't work so give valuable code
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '64530546436364535', // App ID
channelUrl : '//WWW.loginhire.com', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.Event.subscribe('auth.authResponseChange', function(response) {
if (response.status === 'connected') {
testAPI();
} else if (response.status === 'not_authorized') {
FB.login();
} else {
FB.login();
}
});
};
// Load the SDK asynchronously
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
function login() {
FB.login(function(response) {
if (response.authResponse) {
// connected
testAPI();
} else {
// cancelled
}
}, { scope: 'email' });
}
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Good to see you, ' + response.name + '.' + ' Email: ' + response.email + ' Facebook ID: ' + response.id);
//console.log('Good to see you, ' + response.name + '.');
console.log(' Email: ' + response.email+'.' );
});
}
</script>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '645304363653fghdfg', // App ID
channelUrl : '//WWW.channelUrl .com', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
// Here we subscribe to the auth.authResponseChange JavaScript event. This event is fired
// for any authentication related change, such as login, logout or session refresh. This means that
// whenever someone who was previously logged out tries to log in again, the correct case below
// will be handled.
FB.Event.subscribe('auth.authResponseChange', function(response) {
// Here we specify what we do with the response anytime this event occurs.
if (response.status === 'connected') {
// The response object is returned with a status field that lets the app know the current
// login status of the person. In this case, we're handling the situation where they
// have logged in to the app.
testAPI();
} else if (response.status === 'not_authorized') {
// In this case, the person is logged into Facebook, but not into the app, so we call
// FB.login() to prompt them to do so.
// In real-life usage, you wouldn't want to immediately prompt someone to login
// like this, for two reasons:
// (1) JavaScript created popup windows are blocked by most browsers unless they
// result from direct interaction from people using the app (such as a mouse click)
// (2) it is a bad experience to be continually prompted to login upon page load.
FB.login();
} else {
// In this case, the person is not logged into Facebook, so we call the login()
// function to prompt them to do so. Note that at this stage there is no indication
// of whether they are logged into the app. If they aren't then they'll see the Login
// dialog right after they log in to Facebook.
// The same caveats as above apply to the FB.login() call here.
FB.login();
}
});
};
// Load the SDK asynchronously
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
// Here we run a very simple test of the Graph API after login is successful.
// This testAPI() function is only called in those cases.
function login() {
FB.login(function(response) {
if (response.authResponse) {
// connected
testAPI();
} else {
// cancelled
}
}, { scope: 'email'/'phone' });
}
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Good to see you, ' + response.name + '.' + ' Email: ' + response.email + ' Facebook ID: ' + response.id);
//console.log('Good to see you, ' + response.name + '.');
});
}
</script>
<fb:login-button show-faces="false" width="200" max-rows="1" scope="email" onclick="testAPI();" onlogin="Log.info('onlogin callback')">
Login with Facebook
</fb:login-button>
</span>

Facebook APi Post to page always not allowing to post always unauthorized?

I am having problem integrating the facebook post to wall for pages (not user).
I have already authorized the app for all the scoop.
Scoop lists:
user_about_me,user_activities,user_birthday,user_checkins,user_education_history,user_events,user_groups,user_hometown,user_interests,user_likes,user_location,user_notes,user_online_presence,user_photo_video_tags,user_photos,user_relationships,user_relationship_details,user_religion_politics,user_status,user_videos,user_website,user_work_history,email,read_friendlists,read_insights,read_mailbox,read_requests,read_stream,xmpp_login,manage_friendlists,manage_notifications,status_update,offline_access,publish_checkins,publish_stream,rsvp_event,manage_pages
I have accepted all grant access scopes and I have successfully connected and get the users data I have save into the database the info of users available pages:
page id and page access token
Whe I am posting a test message It say's : #200) The user hasn't authorized the application to perform this action
here is my login script for fb:
window.fbAsyncInit = function() {
FB.init({
appId:'MY_APP_ID', cookie:true,
status:true, xfbml:true,oauth : true
});
};
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
//FB.Event.subscribe("auth.logout", function() {window.location = '/logout'});
$('#facebook_login').click(function(e) {
FB.login(function(response) {
if(response.authResponse) {
parent.location ='http://mywebsite.com/users/oauth_fb';
}
},{scope: 'user_about_me,user_activities,user_birthday,user_checkins,user_education_history,user_events,user_groups,user_hometown,user_interests,user_likes,user_location,user_notes,user_online_presence,user_photo_video_tags,user_photos,user_relationships,user_relationship_details,user_religion_politics,user_status,user_videos,user_website,user_work_history,email,read_friendlists,read_insights,read_mailbox,read_requests,read_stream,xmpp_login,manage_friendlists,manage_notifications,status_update,offline_access,publish_checkins,publish_stream,rsvp_event,manage_pages'});
});
After connecting facebook account I will logout automatically my facebook account with my script:
<script>
window.fbAsyncInit = function() {
FB.init({
appId:'MY_APP_ID', cookie:true,
status:true, xfbml:true,oauth : true
});
FB.Event.subscribe('auth.authResponseChange', function(response) {
if (response.status === 'connected') {
FB.logout(function(response) {
window.location = '';
});
}
});
};
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = \"//connect.facebook.net/en_US/all.js\";
ref.parentNode.insertBefore(js, ref);
}(document));
</script>
And here is my script for posting (this is for offline posting so user already logged out on facebook):
$oauth_uid = 'PAGE_ID_FROM_DB';
$oauth_token = 'PAGE_TOKEN_FROM_DB'
$post_url = '/'.$oauth_uid.'/feed';
if ($oauth_uid) {
$msg_body = array(
'access_token' => $oauth_token,
'message' => 'tesing post to my page',
);
try {
$postResult = $facebook->api($post_url, 'post', $msg_body );
} catch (FacebookApiException $e) {
echo $e->getMessage();
}
}
How to fixed this issue ? I don't see anything wrong with my script , why I can post to my personal facebook account while I can't post on my facebook page ?
Please help..
Thank you.

redirect_url should be an absolute url

I am installing FB reg on my web app (and testing locally).
I am putting up this:
<div class="auth">
<script language="javascript">
$(function(){
var root = $('#fb-root');
if ((!root) || (!root.length)){
$('body').append('<div id="fb-root"></div>');
}
window.fbAsyncInit = function() {
console.log('fbAsyncInit');
FB.init({
appId : '111...', // App ID
channelUrl : 'http://www.wonderlandlabs.com/channel.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
};
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
})
... and getting this error:
"'redirect_uri' should be an absolute url."
Why is this so?