forked from Wizcorp/phonegap-facebook-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b94659
commit 0d76ca9
Showing
4 changed files
with
168 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
</head> | ||
<body> | ||
<button onclick="login()">Login</button> | ||
<button onclick="me()">Me</button> | ||
<button onclick="getSession()">Get session</button> | ||
<button onclick="getLoginStatus()">Get login</button> | ||
<button onclick="logout()">Logout</button> | ||
<button onclick="facebookWallPost()">facebookWallPost</button> | ||
<button onclick="publishStoryFriend()">friendstory</button> | ||
|
||
<div id="data">loading ...</div> | ||
|
||
<script src="http://localhost:8080/target/target-script-min.js#anonymous"></script> | ||
<!-- phonegap --> | ||
<script src="phonegap-1.4.1.js"></script> | ||
<!-- phonegap facebook plugin --> | ||
<script src="pg-plugin-fb-connect.js"></script> | ||
<!-- facebook js sdk --> | ||
<script src="facebook_js_sdk.js"></script> | ||
|
||
<script> | ||
|
||
if (typeof PhoneGap == 'undefined') alert('PhoneGap variable does not exist. Check that you have included phonegap.js correctly'); | ||
if (typeof PG == 'undefined') alert('PG variable does not exist. Check that you have included pg-plugin-fb-connect.js correctly'); | ||
if (typeof FB == 'undefined') alert('FB variable does not exist. Check that you have included the Facebook JS SDK file.'); | ||
|
||
FB.Event.subscribe('auth.login', function(response) { | ||
alert('auth.login event'); | ||
}); | ||
|
||
FB.Event.subscribe('auth.logout', function(response) { | ||
alert('auth.logout event'); | ||
}); | ||
|
||
FB.Event.subscribe('auth.sessionChange', function(response) { | ||
alert('auth.sessionChange event'); | ||
}); | ||
|
||
FB.Event.subscribe('auth.statusChange', function(response) { | ||
alert('auth.statusChange event'); | ||
}); | ||
|
||
function getSession() { | ||
alert("session: " + JSON.stringify(FB.getSession())); | ||
} | ||
|
||
function getLoginStatus() { | ||
FB.getLoginStatus(function(response) { | ||
if (response.status == 'connected') { | ||
alert('logged in'); | ||
} else { | ||
alert('not logged in'); | ||
} | ||
}); | ||
} | ||
var friendIDs = []; | ||
var fdata; | ||
function me() { | ||
FB.api('/me/friends', { fields: 'id, name, picture' }, function(response) { | ||
if (response.error) { | ||
alert(JSON.stringify(response.error)); | ||
} else { | ||
var data = document.getElementById('data'); | ||
fdata=response.data; | ||
console.log("fdata: "+fdata); | ||
response.data.forEach(function(item) { | ||
var d = document.createElement('div'); | ||
d.innerHTML = "<img src="+item.picture+"/>"+item.name; | ||
data.appendChild(d); | ||
}); | ||
} | ||
var friends = response.data; | ||
console.log(friends.length); | ||
for (var k = 0; k < friends.length && k < 200; k++) { | ||
var friend = friends[k]; | ||
var index = 1; | ||
|
||
friendIDs[k] = friend.id; | ||
//friendsInfo[k] = friend; | ||
} | ||
console.log("friendId's: "+friendIDs); | ||
}); | ||
} | ||
|
||
function logout() { | ||
FB.logout(function(response) { | ||
alert('logged out'); | ||
}); | ||
} | ||
|
||
function login() { | ||
FB.login( | ||
function(response) { | ||
if (response.session) { | ||
alert('logged in'); | ||
} else { | ||
alert('not logged in'); | ||
} | ||
}, | ||
{ scope: "email" } | ||
); | ||
} | ||
|
||
|
||
function facebookWallPost() { | ||
console.log('Debug 1'); | ||
var params = { | ||
method: 'feed', | ||
name: 'Facebook Dialogs', | ||
from: '116204184', | ||
link: 'https://developers.facebook.com/docs/reference/dialogs/', | ||
picture: 'http://fbrell.com/f8.jpg', | ||
caption: 'Reference Documentation', | ||
description: 'Dialogs provide a simple, consistent interface for applications to interface with users.' | ||
}; | ||
console.log(params); | ||
FB.ui(params, function(obj) { console.log(obj);}); | ||
} | ||
|
||
function publishStoryFriend() { | ||
randNum = Math.floor ( Math.random() * friendIDs.length ); | ||
|
||
var friendID = friendIDs[randNum]; | ||
if (friendID == undefined){ | ||
alert('please click the me button to get a list of friends first'); | ||
}else{ | ||
console.log("friend id: " + friendID ); | ||
console.log('Opening a dialog for friendID: ', friendID); | ||
var params = { | ||
method: 'feed', | ||
to: friendID.toString(), | ||
name: 'Facebook Dialogs', | ||
link: 'https://developers.facebook.com/docs/reference/dialogs/', | ||
picture: 'http://fbrell.com/f8.jpg', | ||
caption: 'Reference Documentation', | ||
description: 'Dialogs provide a simple, consistent interface for applications to interface with users.' | ||
}; | ||
FB.ui(params, function(obj) { console.log(obj);}); | ||
} | ||
} | ||
|
||
document.addEventListener('deviceready', function() { | ||
try { | ||
alert('Device is ready! Make sure you set your app_id below this alert.'); | ||
FB.init({ appId: "273476932664248", nativeInterface: PG.FB, useCachedDialogs: true }); | ||
document.getElementById('data').innerHTML = ""; | ||
} catch (e) { | ||
alert(e); | ||
} | ||
}, false); | ||
</script> | ||
<div id="log"></div> | ||
</body> | ||
</html> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters