Can't load friends images with facebook API - javascript

I'am following a tutorial from Facebook for making a mobile website application.
But i can't load the images from friends.
I get this:
<img src="[object Object]">
It should work, because i copied the entire code from the example (only changed appId)
Here is the full code:
<html>
<head>
<title>Hello World</title>
<meta name="viewport" content="initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<meta property="og:title" content="Hello world" />
<meta property="og:type" content="website" />
<meta property="og:site_name" content="Hello World" />
<meta property="og:description" content="Hello World! This is my mobile web sample app." />
<meta property="og:image" content="http://www.facebookmobileweb.com/hackbook/img/facebook_icon_large.png"/>
</head>
<body>
<div id="fb-root"></div>
<script>
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
<script>
window.fbAsyncInit = function() {
FB.init({ appId: '226909127331855',
status: true,
cookie: true,
xfbml: true,
oauth: true});
FB.Event.subscribe('auth.statusChange', handleStatusChange);
};
</script>
<script>
function handleStatusChange(response) {
document.body.className = response.authResponse ? 'connected' : 'not_connected';
if (response.authResponse) {
console.log(response);
updateUserInfo(response);
}
}
</script>
<div id="login">
<p><button onClick="loginUser();">Login</button></p>
</div>
<div id="logout">
<div id="user-info"></div>
<p><button onClick="FB.logout();">Logout</button></p>
</div>
<script>
function loginUser() {
FB.login(function(response) { }, {scope:'email'});
}
</script>
<style>
body.connected #login { display: none; }
body.connected #logout { display: block; }
body.not_connected #login { display: block; }
body.not_connected #logout { display: none; }
</style>
<div id="user-info"></div>
<script>
function updateUserInfo(response) {
FB.api('/me', function(response) {
document.getElementById('user-info').innerHTML = '<img src="https://graph.facebook.com/' + response.id + '/picture">' + response.name;
});
}
</script>
Get friends<br>
<div id="user-friends"></div>
<script>
function getUserFriends() {
FB.api('/me/friends&fields=name,picture', function(response) {
console.log('Got friends: ', response);
if (!response.error) {
var markup = '';
var friends = response.data;
for (var i=0; i < friends.length && i < 25; i++) {
var friend = friends[i];
markup += '<img src="' + friend.picture + '"> ' + friend.name + '<br>';
}
document.getElementById('user-friends').innerHTML = markup;
}
});
}
</script>
Publish feed story<br>
<script>
function publishStory() {
FB.ui({
method: 'feed',
name: 'I\'m building a social mobile web app!',
caption: 'This web app is going to be awesome.',
description: 'Check out Facebook\'s developer site to start building.',
link: 'http://www.facebookmobileweb.com/hello',
picture: 'http://www.facebookmobileweb.com/hackbook/img/facebook_icon_large.png'
},
function(response) {
console.log('publishStory response: ', response);
});
return false;
}
</script>
Send request<br>
<script>
function sendRequest() {
FB.ui({
method: 'apprequests',
message: 'invites you to learn how to make your mobile web app social',
},
function(response) {
console.log('sendRequest response: ', response);
});
}
</script>
<fb:like></fb:like>
</body>
</html>
Here is the tutorial: https://developers.facebook.com/docs/mobile/web/build/

Try changing your code to this:
'<img src="' + friend.picture.data.url + '"> '
As #Gyan mentioned, take a look at the open graph explorer to see what the underlying data structure looks like.

you are doing only a bit wrong
go for this link face book developer tool for graph api for freindlist link
you will get friends something like
{
"name": "Nishant Porwal",
"id": "522901714",
"picture": {
"data": {
"url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash4/372008_522901714_1470071180_q.jpg",
"is_silhouette": false
}
}
}
and now see your code
'<img src="' + friend.picture + '"> '
you have to parse
you defently find that you are placing an object instead of placing url so change your code and get url because src always work for image url :) might i am given you an idea where you are wrong
change it to
'<img src="' + friend.picture.data.url + '"> '

General advice is to check the object type returned by your method. Since you are being returned an object, there is likely a property like image you can reference from that object... something like objectName.imageURI

Related

How to get the profilepic path after login with facebook

Here i am doing Login with facebook,and also it is working fine,now my question is after login i need the profile pic path,i don't how can get the path,if any one knows please update your answer.as od now i am getting the values like id,name,email but i don't the profilepic path
window.fbAsyncInit = function() {
FB.init({appId: '1990039811315283', status: true, cookie: true, xfbml: true});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
function fetchUserDetail()
{
FB.api('/me?fields=id,name,email', function(responseFromFB){
//console.log("Name: "+ response.name + "\Email: "+ response.email + "ID: "+response.id);
console.log(JSON.stringify(responseFromFB));
var userName = responseFromFB.name;
var userEmail = responseFromFB.email;
var profilePic = '1.png';
var registerFrom = 'Web';
var FCM_Token = '';
$.ajax({
url:'admin/rest/registerFB',
type:'POST',
data: {userName: userName, userEmail: userEmail, profilePic: profilePic, registerFrom: registerFrom, FCM_Token: FCM_Token},
success:function(loginResponse){
if(loginResponse['status']=='success'){
window.location.href = "index.php";
}
},
});
});
}
function checkFacebookLogin()
{
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
fetchUserDetail();
}
else
{
initiateFBLogin();
}
});
}
function initiateFBLogin()
{
FB.login(function(response) {
fetchUserDetail();
}, {scope: 'email'});
}
<html>
<head>
<title>Facebook Login JavaScript Example</title>
<meta charset="UTF-8">
</head>
<body>
<input type="button" class="btn btn-lg btn-fb" value="Sign in using Facebook" scope="public_profile,email" onclick="checkFacebookLogin();"/>
<div id="fb-root"></div>
When you get the response from FB, you'll get the id of the user for your registered App. You can use this id and get the image of the user.
The below code creates an image tag dynamically and adds to the body. add this to your fetchUserDetail() response handler.
let image = document.createElement("img");
image.src = `https://graph.facebook.com/v2.12/${responseFromFB.id}/picture`;
document.body.appendChild(image);
API docs here

Facebook javascript friend list application

I am trying to create a facebook javascript application - that will take an array of facebook id's -- and display them as a list.
Johnny Cash
Roger Maleon
Mealine Pip
[23432432, 1313232, 43534543]
here is the
latest jsfiddle
http://jsfiddle.net/0ht35rpb/94/
-- I've started to try and make the application but its coming up with the error
""An active access token must be used to query information about the current user.""
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title of the document</title>
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
var facebookArray = [23432432, 1313232, 43534543]
var app = {
getFriends : function(){
FB.api('/me?fields=id,name', function(response) {
console.log(response)
if(response.data) {
$.each(response.data,function(index,friend) {
alert(friend.name + ' has id:' + friend.id);
});
} else {
alert("Error!");
}
});
}
}
$(document).ready(function() {
$.ajaxSetup({ cache: true });
$.getScript('//connect.facebook.net/en_US/sdk.js', function(){
FB.init({
appId: '803898723110754',
version: 'v2.7' // or v2.1, v2.2, v2.3, ...
});
$('#loginbutton,#feedbutton').removeAttr('disabled');
FB.getLoginStatus();
app.getFriends();
});
});
//app id
//803898723110754
//client token
//a10b3f9479bac9cce58aeecd8a037a04
</script>
</head>
<body>
</body>
</html>

Sign-in with google account on website

I just started using google API, so i feel like i am walking in the dark.
What i want to do:
It is a very common feature. I want my site to have a Google account Sign-In Button using javascipt, and make sure that a given gmail is valid and maybe extract some basic information from the account.
What do i found:
I have followed the instructions from here:
https://developers.google.com/+/web/signin/javascript-flow .
and copied the code in the last steps of the instructions. I have entered my CLIENT_ID that i got when i followed the instructions in the 'tutorial' but my button just doesn't work. I also searched for some examples and are quite different from the code i found in the google site. I feel that i am missing something (actually i think that i am doing something stupid :) ).
And Here is my code
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
<meta name="google-signin-clientid" content="'MY_CLIENT_ID'.apps.googleusercontent.com" />
<meta name="google-signin-scope" content="https://www.googleapis.com/auth/plus.login" />
<meta name="google-signin-requestvisibleactions" content="http://schema.org/AddAction" />
<meta name="google-signin-cookiepolicy" content="single_host_origin" />
<script src="https://apis.google.com/js/client:platform.js" async defer></script>
<script type="text/javascript">
function signinCallback(authResult) {
if (authResult['status']['signed_in']) {
// Update the app to reflect a signed in user
// Hide the sign-in button now that the user is authorized, for example:
document.getElementById('signinButton').setAttribute('style', 'display: none');
} else {
// Update the app to reflect a signed out user
// Possible error values:
// "user_signed_out" - User is signed-out
// "access_denied" - User denied access to your app
// "immediate_failed" - Could not automatically log in the user
console.log('Sign-in state: ' + authResult['error']);
}
}
function render() {
alert("1");
// Additional params including the callback, the rest of the params will
// come from the page-level configuration.
var additionalParams = {
'callback': signinCallback
};
alert("2");
// Attach a click listener to a button to trigger the flow.
var signinButton = document.getElementById('signinButton');
signinButton.addEventListener('click', function() {
gapi.auth.signIn(additionalParams); // Will use page level configuration
alert("3");
});
}
</script>
</head>
<body>
<button id="signinButton">Sign in with Google</button>
</body>
</html>
I have added some alerts, but nothing pops-up and did not used anywhere the 'client secret' password or the JavaScript origins. Also, in the place of 'MY_CLIENT_ID' is actually my client ID.
I don't know if this makes any difference, but my site is not yet on a server. Just working locally (with internet of course!)
Do you know what i got wrong?
Check your console, maybe there are some errors.
Try this example from https://google-developers.appspot.com/+/demos/signin_demo_trigger:
<html>
<head>
<title>Google+ Sign-in button demo: JavaScript flow</title>
<style type="text/css">
html, body { margin: 0; padding:0;}
#signin-button {
padding: 5px;
}
#oauth2-results pre { margin: 0; padding:0; width: 600px;}
.hide { display: none;}
.show { display: block;}
</style>
<script type="text/javascript">
var loginFinished = function(authResult) {
if (authResult) {
console.log(authResult);
var el = document.getElementById('oauth2-results');
var label = '';
toggleDiv('oauth2-results');
if (authResult['status']['signed_in']) {
label = 'User granted access:';
gapi.auth.setToken(authResult);
} else {
label = 'Access denied: ' + authResult['error'];
}
el.innerHTML =
label + '<pre class="prettyprint"><code>' +
// JSON.stringify doesn't work in IE8.
'{<br />' +
' "id_token" : "' + authResult['id_token'] +'",<br />' +
' "access_token" : "' + authResult['access_token'] + '",<br />' +
' "state" : "' + authResult['state'] + '",<br />' +
' "expires_in" : "' + authResult['expires_in'] + '",<br />' +
' "error" : "' + authResult['error'] + '",<br />' +
' "error_description" : "' + authResult['error_description'] + '",<br />' +
' "authUser" : "' + authResult['authuser'] + '",<br />' +
' "status" : {"' + '<br />' +
' "google_logged_in" : "' + authResult['status']['google_logged_in'] + '",<br />' +
' "method" : "' + authResult['status']['method'] + '",<br />' +
' "signed_in" : "' + authResult['status']['signed_in'] + '"<br />' +
' }<br />' +
'}</code></pre>';
} else {
document.getElementById('oauth2-results').innerHTML =
'Empty authResult';
}
};
function toggleDiv(id) {
var div = document.getElementById(id);
if (div.getAttribute('class') == 'hide') {
div.setAttribute('class', 'show');
} else {
div.setAttribute('class', 'hide');
}
}
var options = {
'callback' : loginFinished,
'approvalprompt' : 'force',
'clientid' : '841077041629.apps.googleusercontent.com',
'requestvisibleactions' : 'http://schema.org/CommentAction http://schema.org/ReviewAction',
'cookiepolicy' : 'single_host_origin'
};
function startFlow(){
toggleDiv('startFlow');
gapi.auth.signIn(options);
}
</script>
<script src="https://apis.google.com/js/client:platform.js" type="text/javascript"></script>
</head>
<body>
<div id="startFlow">
<a class="button button-blue" href="javascript:startFlow();">Click me</a>
to trigger the sign-in flow with
<a href="/+/web/signin/reference#gapi.auth.signIn"
target="_parent"><code>gapi.auth.signIn()</code></a>
</div>
<div id="oauth2-results" class="hide"></div>
<div style="font: 12px sans-serif, Arial; margin-left: 0.5em; margin-top: 0.5em">Reload the example or open in a new window</div>
</body>
</html>
<!-- Sign in with Google+ only work on working website -->
<html lang="en">
<head>
<script src="https://apis.google.com/js/platform.js?onload=renderApp" async defer></script>
</head>
<body>
<div class="g-signin2" id="customBtn">Sign in with Google+</div>
<script>
function onSignIn(googleUser) {
// Useful data for your client-side scripts:
var profile = googleUser.getBasicProfile();
console.log("ID: " + profile.getId()); // Don't send this directly to your server!
console.log('Full Name: ' + profile.getName());
console.log('Given Name: ' + profile.getGivenName());
console.log('Family Name: ' + profile.getFamilyName());
console.log("Image URL: " + profile.getImageUrl());
console.log("Email: " + profile.getEmail());
// The ID token you need to pass to your backend:
var id_token = googleUser.getAuthResponse().id_token;
console.log("ID Token: " + id_token);
};
</script>
<script>
var renderApp = function() {
// GOOGLE_CLIENT_ID should be create from https://developers.google.com/identity/sign-in/web/devconsole-project
gapi.load('auth2', function(){
auth2 = gapi.auth2.init({
client_id: 'GOOGLE_CLIENT_ID.apps.googleusercontent.com',
cookiepolicy: 'single_host_origin',
});
attachSignin('customBtn'); //Function called for click
});
};
function attachSignin(customBtn) {
auth2.attachClickHandler(customBtn, {}, onSignIn, function(error) {
console.log(JSON.stringify(error, undefined, 2));
});
}
</script>
</body>
</html>

communication from javascript to objective-C

I am loading a HTML file file from server inside UIWebView. In HTML file, we have external links to open and a Javascript function is written to handle that events.I want to open that hyperlinks inside a seperate new webview within the app.
Is there any way that server side javascript method notify to objective-C or any callback function which will call in objective-C and then i can do someting in my code? i have seen the example of WEBViewJavaScriptBridge to communicate between javascript and objective C. but they are using the local HTML file to load and communicate.Bt my HTML file is on server side.It would be great if anyone can help on this.
I am puuting a sample HTML file here. We have two hypelinks "Open" and "Close" on taping on open button a function is called that show alert. so instead of alert i want to pass the retuen callback to objective-C code.
Here it is:-
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width = device-width, initial-scale = 1.0, maximum-scale = 1.0, minimum-scale = 1.0, user-scalable=no"/>
<meta name="HandheldFriendly" content="True"/>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<title>Test HTML</title>
<script type="text/javascript">
function open(url, offset){
alert("Open Webview with url:"+ url + " & Offset: " + offset);
}
function close(url, offset){
alert("close webview");
}
</script>
</head>
<body>
Open<br>
Close
</body>
</html>
I used webviewjavascriptbridge to communicate javascript and objective C code.
In this example code, note the global variable of bridge.
<!doctype html>
<html><head>
<style type='text/css'>
html { font-family:Helvetica; color:#222; }
h1 { color:steelblue; font-size:24px; margin-top:24px; }
button { margin:0 3px 10px; font-size:12px; }
.logLine { border-bottom:1px solid #ccc; padding:4px 2px; font-family:courier; font-size:11px; }
</style>
</head><body>
<h1>WebViewJavascriptBridge Demo</h1>
<script>
window.onerror = function(err) {
alert('window.onerror: ' + err)
}
var bridge;
document.addEventListener('WebViewJavascriptBridgeReady', onBridgeReady, false)
function onBridgeReady(event){
alert("Onbridge ready call");
bridge = event.bridge
var uniqueId = 1
function log(message, data) {
var log = document.getElementById('log')
var el = document.createElement('div')
el.className = 'logLine'
el.innerHTML = uniqueId++ + '. ' + message + (data ? ': ' + JSON.stringify(data) : '')
if (log.children.length) { log.insertBefore(el, log.children[0]) }
else { log.appendChild(el) }
}
bridge.init(function(message) {
log('JS got a message', message)
})
bridge.registerHandler('open', function(data, response) {
log('JS handler testJavascriptHandler was called', data)
response.respondWith({ 'Javascript Says':'open open open!' })
})
bridge.registerHandler('testJavascriptHandler', function(data, response) {
log('JS handler testJavascriptHandler was called', data)
response.respondWith({ 'Javascript Says':'Right back atcha!' })
})
var button = document.getElementById('buttons').appendChild(document.createElement('button'))
button.innerHTML = 'Send message to ObjC'
button.ontouchstart = function(e) {
e.preventDefault()
bridge.send('Hello from JS button')
}
document.body.appendChild(document.createElement('br'))
var callbackButton = document.getElementById('buttons').appendChild(document.createElement('button'))
callbackButton.innerHTML = 'Fire testObjcCallback'
callbackButton.ontouchstart = function(e) {
e.preventDefault()
log("Calling handler testObjcCallback")
bridge.callHandler('testObjcCallback', {'foo': 'bar'}, function(response) {
log('Got response from testObjcCallback', response)
})
}
}
function open(url, offset,e)
{
alert(bridge);
//alert("Open Webview with url:Yes Got it");
// alert(document.getElementById(offset).href);
// var bridge = event.bridge;
// alert(bridge);
window.location = url+'?offset='+offset//'myapp:myaction:url:offset'
//requestFromObjc("buttonColor&someParam=1");
}
function close()
{
alert("Open Webview with url:"+ url + " & Offset: " + offset);
}
function requestFromObjc(functionName, objcResult, callback)
{
if (!objcResult)
{
window.location = 'myapp:myaction:param1:param2'
// window.location = "myapp://objcRequest?function=" + functionName + "&callback=" + arguments.callee.name + "&callbackFunc=" + arguments.callee.caller.name;
}
else
{
window[callback](objcResult);
}
}
</script>
<div id='buttons'></div> <div id='log'></div>
<body>
<a id="55" href="javascript:open('http://www.tcm.com', '55',this)">Open</a><br>
Close
</body>
</body></html>
Reference: https://github.com/marcuswestin/WebViewJavascriptBridge
You can communicate with your HTML from objective c with the following webView delagate methods...
- (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
Please go through the usage of these methods...
I hope this may help you

adding events information to the facebook profile from 3rd party website

I am trying to add events information to the facebook users profile from a 3rd party website using Javascript SDK provided by facebook. I just googled for few tutorials and I got this links
http://thinkdiff.net/facebook/graph-api-javascript-base-facebook-connect-tutorial/
http://www.masteringapi.com/tutorials/how-to-ask-for-extended-permission-in-your-facebook-application/32/
http://www.masteringapi.com/tutorials/how-to-create-facebook-events-using-graph-api/49/#using_the_js-sdk
I tried with the combination of login logout and session handling
this is the code which I am run just to test whether it works or not.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function()
{
FB.init({
appId: '207712505927107',
status: true,
cookie: true,
xfbml: true
});
/* All the events registered */
FB.Event.subscribe('auth.login', function(response) {
// do something with response
login();
});
FB.Event.subscribe('auth.logout', function(response) {
// do something with response
logout();
});
FB.getLoginStatus(function(response)
{
if (response.session)
{
// logged in and connected user, someone you know
login();
}
});
};
(function()
{
var e = document.createElement('script');
e.type = 'text/javascript';
e.src = document.location.protocol
+ '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
function login()
{
FB.api('/me', function(response)
{
document.getElementById('login').style.display = "block";
var loggedInMessage = response.name + " successfully logged in!";
document.getElementById('login').innerHTML = loggedInMessage;
});
}
function logout()
{
document.getElementById('login').style.display = "none";
}
//addevent to facebook profile
function addevents()
{
FB.api('/me/events', 'post', {
name: "JS-SDK Event",
start_time: 1272718027,
location: "Beirut",
privacy_type: "OPEN"
}, function(resp) {
alert(resp.id);
});
}
</script>
<p>
<fb:login-button
autologoutlink="true"
perms="email,user_birthday,status_update,publish_stream,create_event">
</fb:login-button>
</p>
<p>
Add Events
</p>
<br />
<br />
<br />
<br />
<div id="login" style ="display:none"></div>
<div id="name"></div>
</body>
</html>
When I click on the add event page I am getting "undefined". Iam not able to add events to facebook profle. Kindly help me
I would try your code again, and maybe console.log(resp) in your callback method for the addevents function. I tested your code on fbrell.com and it seemed to work perfectly and as expected.
edit: after a little research (and your fixed code..) I found that the fb:login button doesn't ensure that your application has the correct permissions that the perms parameter requests. We find this out when we do a Graph request and it fails. So we catch the error, and then launch the Login modal via the FB.login method, and ask for the create_event permission. When the user accepts that dialog, we retry creating the event.
<fb:login-button
autologoutlink="true"
perms="email,user_birthday,status_update,publish_stream,create_event">
</fb:login-button>
create
<script>
FB.XFBML.parse();
document.getElementById('create_event').onclick = function() { create_event(); }
function create_event()
{
FB.api('/me/events', 'post', {
name: "JS-SDK Event",
start_time: 1272718027,
location: "Anywhere USA",
privacy_type: "OPEN"
}, function(resp) {
if (typeof resp.error != 'undefined')
{ /*this failed. most likely because we don't have the extended permission
for create_event. so lets check for it, ask for it, and try to create
the event again. but first, we'll make sure that the error message says
something about 'create_event' so we don't launch an infinite loop
*/
if (resp.error.message.match(/create_event/))
{
FB.login(function(response)
{
if (response.session
&& response.status == 'connected'
&& response.perms.match(/create_event/))
{
//this user is connected & we have create event permission.
create_event();
}
},
{
perms: 'create_event'
});
}
}
});
}
</script>
Working code on fbrell.com: http://fbrell.com/saved/17c7b60eab91e6736a2a10c87d53c5b8
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({appId: '207712505927107', status: true, cookie: true, xfbml: true});
/* All the events registered */
FB.Event.subscribe('auth.login', function(response) {
// do something with response
login();
});
FB.Event.subscribe('auth.logout', function(response) {
// do something with response
logout();
});
FB.getLoginStatus(function(response) {
if (response.session) {
// logged in and connected user, someone you know
login();
}
});
};
(function() {
var e = document.createElement('script');
e.type = 'text/javascript';
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
function login(){
FB.api('/me', function(response) {
document.getElementById('login').style.display = "block";
document.getElementById('login').innerHTML = response.name + " succsessfully logged in!";
});
}
function logout(){
document.getElementById('login').style.display = "none";
}
//add events
function addevents() {
FB.api('/me/events','post',{
name:"awesome event",
start_time:1272718027,
location:"Bengaluru",
privacy_type:"OPEN",
description:"U r invited !!!"
}, function(resp) {
document.write(resp.id);
});
}
//checking persmission
function check_perm() {
FB.api({ method: 'users.hasAppPermission', ext_perm: 'create_event' }, function(resp)
{
if (resp === "1") {
alert('Permission granted');
} else {
alert("Permission not granted");
}
});
}
</script>
<p>Please click on Login button first </p>
<p><fb:login-button autologoutlink="true" perms="create_event"></fb:login-button></p>
<p> Please click on check permissions first </p>
check permissions
<p> now u r all set to add events to facebook </p>
<p>
Add Events
</p>
<br /><br /><br />
<div id="login" style ="display:none"></div>
<div id="name"></div>
</body>
</html>

Categories