Post status when user first logs in with Facebook - php

I have now managed to get a status posted when a user clicks a link. I would now like a status to be posted when they first login with Facebook and accept the permissions.
Please help! I am using this code for the login button:
<fb:login-button ></fb:login-button>
Be specific with me I'm new to the Facebook Connect.

Since you managed to authenticate a user and post from a link, then things will be easy, just on the auth.login event call your posting method, something like this would do:
window.fbAsyncInit = function() {
FB.init({appId: '<?php echo $this->facebook->getAppId(); ?>', status: true, cookie: true,
xfbml: true});
FB.Event.subscribe('auth.login', function() {
postStatus();
});
};
(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 postStatus(){
var body = 'Reading Connect JS documentation';
FB.api('/me/feed', 'post', { message: body }, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
}
Result:
EDIT:
Also make sure you have the right permissions in your case publish_stream:
<fb:login-button perms="read_stream,publish_stream"></fb:login-button>

Just modify this code
<div id="fb-root"></div>
<script type="text/javascript">
var uid;
window.fbAsyncInit = function() {
FB.init({appId: 'APP_ID', status: true, cookie: true, xfbml: false});
};
(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);
}());
window.fbAsyncInit = function() {
FB.init({appId: 'APP_ID', 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 graphStreamPublish(){
var body = document.getElementById("txtTextToPublish").value;
FB.api('/me/feed', 'post', { message: body }, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
}
function fqlQuery(){
FB.api('/me', function(response) {
var query = FB.Data.query('select name,email,hometown_location, sex, pic_square from user where uid={0}', response.id);
query.wait(function(rows) {
uid = rows[0].uid;
document.getElementById('name').innerHTML =
'Your name: ' + rows[0].name + "<br />" +
'Your email: ' + rows[0].email + "<br />" +
'Your hometown_location: ' + rows[0].hometown_location + "<br />" +
'Your sex: ' + rows[0].sex + "<br />" +
'Your uid: ' + rows[0].uid + "<br />" +
'<img src="' + rows[0].pic_square + '" alt="" />' + "<br />"
'<fb:multi-friend-selector actiontext="Select the friends you want to invite. (All of them.)" rows="3"/>';
});
});
}
function getFriends(){
var theword = '/me/friends';
var params = new Array(uid);
FB.api(theword,params, function(response) {
var divInfo = document.getElementById("divInfo");
var friends = response.data;
divInfo.innerHTML += '<h1 id="header">Friends</h1><ul id="list">';
for (var i = 0; i < friends.length; i++) {
divInfo.innerHTML += friends[i].id+" "+friends[i].name+"<img src=https://graph.facebook.com/"+friends[i].id+"/picture/>";
// divInfo.innerHTML+= '<fb:name useyou=false uid=100001248074891 firstnameonly=true></fb:name>';//'<fb:name useyou=false uid='+friends[i].id+' firstnameonly=true></fb:name>';
}
});
}
function share(){
var share = {
method: 'stream.share',
u: document.getElementById('txtShare').value
};
FB.ui(share, function(response) { console.log(response); });
}
</script>
<fb:login-button
autologoutlink="true"
perms="email,user_birthday,status_update,publish_stream"></fb:login-button>

Related

Uncaught TypeError: Cannot read properties of undefined (reading 'geometry') at Object.success

Map is not showing due to that error
Uncaught TypeError: Cannot read properties of undefined (reading 'geometry') at Object.success
Here is my map code:
<script>
var mapArea =
'<p class="note-for-location text-center">Select Your Business location by clicking on map and then
save location</p><input type="hidden" name="latitude" id="latitude"/><input type="hidden"
name="longitude" id="longitude"/><div id="map"></div>';
function get_map() {
$("#property_google_map").html(mapArea);
var city_name = escape(document.getElementById("business_cityy").value);
var subarea_name = escape(document.getElementById("sub_area").value);
var locality_name = document.getElementById("locality").value;
if (locality_name == "Unlisted Locality" && subarea_name == "Unlisted Area") {
var address = city_name + " Pakistan";
var zoming_view = 8;
} else if (locality_name == "Unlisted Locality" && subarea_name != "Unlisted Area") {
var address = subarea_name + " " + city_name + " Pakistan";
var zoming_view = 12;
} else {
var address = locality_name + " " + subarea_name + " " + city_name + " Pakistan";
var zoming_view = 15;
}
$.ajax({
url: "https://maps.googleapis.com/maps/api/geocode/json?address=" + address +
"&AIzaSyAPpVcdmE4Lr3dPpuWK2GAH8I42rsZz-Io",
type: "POST",
success: function (res) {
$("#latitude").val(res.results[0].geometry.location.lat);
$("#longitude").val(res.results[0].geometry.location.lng);
initMap(res.results[0].geometry.location.lat, res.results[0].geometry.location.lng,
zoming_view);
},
});
}
var map;
var marker;
var infowindow;
var messagewindow;
var confirmForm =
'<div id="form"><fieldset class="google-field-set"><legend class="google-legend"> Please confirm
your location </legend><table><tr><td></td> <td><input type="hidden" id="name"/></td></tr><tr><td>
</td><td><input type="hidden" id="address" /></td></tr><tr><td></td><td><input type="hidden"
id="type"/></td></td></tr> <tr><td></td><td><input type="button" value="Save" class="google-save-
button" onclick="saveData();"/></td></tr></table></fieldset></div>';
var locationSaved = '<div id="message">Location saved</div>';
function initMap(a, b, z) {
var california = { lat: parseFloat(a), lng: parseFloat(b) };
map = new google.maps.Map(document.getElementById("map"), {
center: california,
zoom: parseInt(z),
});
var image = "images/marker-64.png";
marker2 = new google.maps.Marker({
position: { lat: parseFloat(a), lng: parseFloat(b) },
map: map,
icon: image,
});
infowindow = new google.maps.InfoWindow({
content: confirmForm,
});
messagewindow = new google.maps.InfoWindow({
content: locationSaved,
});
var image = "images/marker-64.png";
google.maps.event.addListener(map, "click", function (event) {
marker2.setOpacity(0.0);
if (marker != null) {
//already set marker to clear
marker.setMap(null);
marker = null;
}
marker = new google.maps.Marker({
position: event.latLng,
map: map,
icon: image,
// draggable: true,
visible: true,
});
if (infowindow) {
infowindow.close();
}
infowindow = new google.maps.InfoWindow({
content: confirmForm,
// maxWidth: 300
});
infowindow.open(map, marker);
//google.maps.event.addListener(marker, 'click', function() {
// infowindow.open(map, marker);
//});
});
}
function saveData() {
var name = escape(document.getElementById("business_city").value);
var address = escape(document.getElementById("sub_area").value);
var type = document.getElementById("locality").value;
var latlng = marker.getPosition();
$("#latitude").val(latlng.lat());
$("#longitude").val(latlng.lng());
var url = "add_latlng.php?name=" + name + "&address=" + address + "&type=" + type + "&lat=" +
latlng.lat() + "&lng=" + latlng.lng();
downloadUrl(url, function (data, responseCode) {
if (responseCode == 200) {
infowindow.close();
messagewindow.open(map, marker);
}
});
}
function downloadUrl(url, callback) {
var request = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
request.onreadystatechange = function () {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request.responseText, request.status);
}
};
request.open("GET", url, true);
request.send(null);
}
function doNothing() {}
</script>
<script async defer src="https://maps.googleapis.com/maps/api/js?
key=AIzaSyAPpVcdmE4Lr3dPpuWK2GAH8I42rsZz-Io"></script>
I am trying to find the solution but not understanding the problem.
For res.results[0].geometry to work, your server needs to support that structure.
For example if you try:
console.log('my-response type:', typeof res);
console.log('my-response content:', JSON.stringify(res, null, 2));
The output should be something like:
my-response type: object
my-response content: {
"results": [
"geometry": {
"location": {
"lat": 123,
"lng": 456
}
}
]
}
But as mentioned in comments, your response was:
{
"results": [],
"status": "REQUEST_DENIED"
}
Note:
If stringify fails, that is not valid JSON, but try:
const filterRecursion = function () {
const seen = new WeakSet();
return function (key, value) {
if (value && typeof value === "object") {
if (seen.has(value)) {
// Ignore:
return;
}
seen.add(value);
}
// Include:
return value;
};
};
console.log('my-response content:', JSON.stringify(res, filterRecursion(), 2));

Why isn't my jQuery .ajaxForm code working?

I'm hoping someone can help me...
Basically, neither if (data.status=='error') { or } else if (data.status=='success') { appear to be getting called yet the data is being inserted into the database fine.
add_alarm_code.php;
<?php
require_once('../inc/config.php');
$con = mysqli_connect(DB_HOST,DB_USER,DB_PASS,DB_NAME);
// define and escape each POST as a variable
foreach ($_POST as $key => $value) {
if (!empty($value)) {
${$key} = mysqli_real_escape_string($con, $value);
}
}
// insert data into database
$sql="INSERT INTO alarm_code (
alarm_code_property,
alarm_code_code,
alarm_code_notes,
alarm_code_date_added
)
VALUES (
'$alarm_code_property',
'$alarm_code_code',
'$alarm_code_notes',
'" . date('Y-m-d') . "'
)";
if (!mysqli_query($con,$sql)) {
echo '{ "status": "error", "message": "Error Inserting Alarm Code Data into Database: ' . mysqli_error($con) . '" }';
} else {
echo '{ "status": "success", "message": "The alarm code has successfully been added to the system. The page will now refresh." }';
}
mysqli_close($con);
?>
jQuery on view_property.php;
// add alarm code submit form
$('#add_alarm_code').ajaxForm({
dataType: 'json',
success: processJson,
error: function (xmlRequest, textStatus, errorThrown) {
alert(errorThrown);
}
});
function processJson(data) {
if (data.status=='error') {
alert('Error 1');
$('#ajax_form_status_alarm_code').removeClass('green_background')
$('#ajax_form_status_alarm_code').addClass('red_background')
$('#ajax_form_status_alarm_code').html(data.message);
alert('Error 2');
} else if (data.status=='success') {
$('#add_alarm_code').clearForm();
$('#ajax_form_status_alarm_code').removeClass('red_background')
$('#ajax_form_status_alarm_code').addClass('green_background')
$('#ajax_form_status_alarm_code').html(data.message);
setTimeout(function() {
var currentURL = window.location.href;
var currentHashValue = window.location.hash;
if (currentHashValue!='') {
location.reload(true);
} else {
window.location.href += "#keys";
location.reload(true);
}
}, 3000);
}
}
form on view_property.php (the form is in a hidden div as it loads in a fancybox/lightbox)
echo '<div style="display:none">';
echo '<form id="add_alarm_code" action="' . SITE_AJAX . 'add_alarm_code.php" method="post">';
echo '<input type="hidden" id="alarm_code_property" name="alarm_code_property" value="' . $property_id . '">';
echo '<fieldset><legend>Add an Alarm Code</legend>
<table class="nobord">';
echo '<tr><td><label for="alarm_code_code">Alarm Code:</label></td>
<td><input type="text" id="alarm_code_code" name="alarm_code_code" maxlength="10" required></td></tr>';
echo '<tr><td><label for="alarm_code_notes">Notes:</label></td>
<td><textarea id="alarm_code_notes" name="alarm_code_notes" rows="6" cols="35"></textarea></td></tr>';
echo '<tr><td colspan="2"><input type="submit" value="Save"></td></tr>';
echo '</table>';
echo '<div id="ajax_form_status_alarm_code" class="ajax_form_status"></div>';
echo '</fieldset></form>';
echo '</div>';
entire jQuery on view_property.php (in case it helps find a bug!);
<script>
$(document).ready(function() {
// tab functionality on load
$(function(e) {
// define variables
var currentAttrValue = window.location.hash;
if (currentAttrValue!='') {
// show/hide tabs
jQuery('.tabs ' + currentAttrValue).fadeIn(400).siblings().hide();
// change/remove current tab to active
jQuery(currentAttrValue).parent('li').addClass('active').siblings().removeClass('active');
e.preventDefault();
}
});
// tab functionality on click
jQuery('.tabs .tab-links a').on('click', function(e) {
var currentAttrValue = jQuery(this).attr('href');
// show/hide tabs
jQuery('.tabs ' + currentAttrValue).fadeIn(400).siblings().hide();
// change/remove current tab to active
jQuery(this).parent('li').addClass('active').siblings().removeClass('active');
e.preventDefault();
});
// fancybox
$(".fancybox").fancybox({
closeBtn : true,
modal : false
});
// apply validation
$( "#add_certificate" ).validate({
errorClass: "error-class",
});
$( "#add_keys" ).validate({
errorClass: "error-class",
});
$( "#add_alarm_code" ).validate({
errorClass: "error-class",
});
// add certificate submit form
$('#add_certificate').ajaxForm({
dataType: 'json',
success: processJson,
});
function processJson(data) {
if (data.status=='error') {
$('#ajax_form_status_certificate').removeClass('green_background')
$('#ajax_form_status_certificate').addClass('red_background')
$('#ajax_form_status_certificate').html(data.message);
} else if (data.status=='success') {
$('#add_certificate').clearForm();
$('#ajax_form_status_certificate').removeClass('red_background')
$('#ajax_form_status_certificate').addClass('green_background')
$('#ajax_form_status_certificate').html(data.message);
setTimeout(function(){
var currentURL = window.location.href;
var currentHashValue = window.location.hash;
if (currentHashValue!='') {
location.reload(true);
} else {
window.location.href += "#certificates";
location.reload(true);
}
}, 3000);
}
}
$( "#add_1_year" ).click(function() {
if ($('#certificate_start_date').val()!='') {
var expiry_date = moment($('#certificate_start_date').val()).add(1, 'year').format("YYYY-MM-DD");
$('#certificate_expiry_date').val(expiry_date);
} else {
alert('Please enter the certificate start date.');
}
});
// add alarm code submit form
$('#add_alarm_code').ajaxForm({
dataType: 'json',
success: processJson,
error: function (xmlRequest, textStatus, errorThrown) {
alert(errorThrown);
}
});
function processJson(data) {
if (data.status=='error') {
alert('Error 1');
$('#ajax_form_status_alarm_code').removeClass('green_background')
$('#ajax_form_status_alarm_code').addClass('red_background')
$('#ajax_form_status_alarm_code').html(data.message);
alert('Error 2');
} else if (data.status=='success') {
$('#add_alarm_code').clearForm();
$('#ajax_form_status_alarm_code').removeClass('red_background')
$('#ajax_form_status_alarm_code').addClass('green_background')
$('#ajax_form_status_alarm_code').html(data.message);
setTimeout(function() {
var currentURL = window.location.href;
var currentHashValue = window.location.hash;
if (currentHashValue!='') {
location.reload(true);
} else {
window.location.href += "#keys";
location.reload(true);
}
}, 3000);
}
}
// add keys submit form
$('#add_keys').ajaxForm({
dataType: 'json',
success: processJson,
});
function processJson(data) {
if (data.status=='error') {
$('#ajax_form_status_keys').removeClass('green_background')
$('#ajax_form_status_keys').addClass('red_background')
$('#ajax_form_status_keys').html(data.message);
} else if (data.status=='success') {
$('#add_keys').clearForm();
$('#ajax_form_status_keys').removeClass('red_background')
$('#ajax_form_status_keys').addClass('green_background')
$('#ajax_form_status_keys').html(data.message);
setTimeout(function(){
var currentURL = window.location.href;
var currentHashValue = window.location.hash;
if (currentHashValue!='') {
location.reload(true);
} else {
window.location.href += "#keys";
location.reload(true);
}
}, 3000);
}
}
});
</script>

My chat website(php+ajax) makes my browser stuck

This is the script I use for various purposes like scrolling, getting the data from php etc:
<script>
$(document).ready(function(){
$("#full_chat").animate({ scrollTop: $('#full_chat')[0].scrollHeight+1000}, 1500);
setInterval(function refreshPage() {
var user=$("#head").text();
$.post("retrieve.php",{ user:user }, function(data,status){
if($.trim(data)!="0"){
$("#full_chat").append("<span class='you'>"+data+"</span>");
$('#full_chat').emoticonize();
window.onblur = function () {
$('#full_chat').bind("DOMSubtreeModified",function(){
$.titleAlert("New Message!", {
requireBlur:true,
stopOnFocus:true,
//duration:10000,
//interval:500
});
});
}
}
}); }, 1500);
$("#form").on('submit',function (e) {
e.preventDefault();
var user=$("#head").text();
var dt = new Date();
var time = dt.getHours() + ":" + dt.getMinutes() + ":" + dt.getSeconds();
var txt= $("#chat_input").val();
$.post("chat.php",{ txt:txt,user:user,time:time },function(data,status){
if(data=="OFFLINE"){
$("#full_chat").append("User not available right now<br>");
}else{
$("#full_chat").append("("+time+") ").append("<span class='me'>"+"Me: "+txt+"</span><br>").emoticonize({delay: 1,animate:false});
}
});
$("#full_chat").animate({ scrollTop: $('#full_chat')[0].scrollHeight+1000}, 1500);
$('#chat_input').val('');
});
});
</script>
This is the PHP code I use to get the chats from database:
<?php
session_start();
$other_user=$_POST['user'];
$flag=$_POST['flag'];
include_once('db.php');
$uname=$_SESSION['username'];
//date_default_timezone_set('Asia/Kolkata');
$q="select message,sender,time from chat where username='$uname' and delivered=0 and sender='$other_user' order by time ASC";
$qe = mysqli_query($con,$q);
$q1="UPDATE chat SET delivered=1 WHERE username='$uname' and sender='$other_user'" ;
$qe1 = mysqli_query($con,$q1);
if($r=mysqli_fetch_array($qe)) {
echo "(".$r['2'].") ". $r['1'].": ".$r['0']."<br>";
}else {
echo "0";
}
mysqli_close($con);
?>
What may be the reason for the problem? Is it the page refresh that happens every 1.5 seconds or something else?
This is just to give you an idea, it is not tested.
<script>
$(document).ready(function() {
var user = $("#head").text();
var postTimeout = 0;
var refreshPage = function(postInterval, postData) {
$.post("retrieve.php", postData, function(data, status) {
if (!postTimeout) {
postTimeout = setTimeout(function() {
refreshPage(postInterval, postData);
postTimeout = 0;
}, postInterval);
}
if ($.trim(data) != "0") {
$("#full_chat").append("<span class='you'>" + data + "</span>");
$('#full_chat').emoticonize();
window.onblur = function() {
$('#full_chat').bind("DOMSubtreeModified", function() {
$.titleAlert("New Message!", {
requireBlur: true,
stopOnFocus: true,
//duration:10000,
//interval:500
});
});
}
}
});
}
$("#full_chat").animate({
scrollTop: $('#full_chat')[0].scrollHeight + 1000
}, 1500);
refreshPage(1500, {user: user});
$("#form").on('submit', function(e) {
e.preventDefault();
var user = $("#head").text();
var dt = new Date();
var time = dt.getHours() + ":" + dt.getMinutes() + ":" + dt.getSeconds();
var txt = $("#chat_input").val();
$.post("chat.php", {
txt: txt,
user: user,
time: time
}, function(data, status) {
if (data == "OFFLINE") {
$("#full_chat").append("User not available right now<br>");
} else {
$("#full_chat").append("(" + time + ") ").append("<span class='me'>" + "Me: " + txt + "</span><br>").emoticonize({
delay: 1,
animate: false
});
}
});
$("#full_chat").animate({
scrollTop: $('#full_chat')[0].scrollHeight + 1000
}, 1500);
$('#chat_input').val('');
});
});
</script>

Web Mobile Application Facebook OAuth

I am trying to go through this sample https://github.com/blackberry/BB10-WebWorks-Samples/blob/master/Twitter-OAuth-1/README.md
Although, I keep getting the following error:
Error in getAuthorization: ReferenceError:Can't find variable: facebookOptions
Here is my code for my javascript OAuth.js
function initApp() {
try {
// facebook oauth setup
facebookOptions = {
clientId: '############',
clientSecret: '######################',
// we use a php script on a server because facebook doesn't allow for local:/// callbacks
// at this time. the php simply redirects us back to 'local:///index.html'
redirectUri: 'http://###########.com/redirect.php'
};
// here we check for query strings in window.location when the app loads. This is because facebook is calling back
// to our callbackUrl. When the app initializes, and there is a query string, it checks if the user
// authorized the app or not
var query = window.location.search;
authCode = null;
authCode = query.split('code=');
authCode = authCode[1] || null;
// we've got an auth code, let's exchange that for an access token
if (authCode !== null) {
getAccessToken();
}
} catch (e) {
alert('Error in initApp: ' + e);
}
}
// first, we get the user to authorize with the service and allow our app access
function getAuthorization() {
try {
showMessage('Contacting Facebook...');
window.location.replace('https://www.facebook.com/dialog/oauth?client_id=' + facebookOptions.clientId + '&redirect_uri=' + facebookOptions.redirectUri + '&scope=publish_stream,read_stream');
} catch (e) {
alert('Error in getAuthorization: ' + e);
}
}
// exchange our 'access code' for an 'access_token'
function getAccessToken() {
try {
var url = 'https://graph.facebook.com/oauth/access_token?client_id=' + facebookOptions.clientId + '&redirect_uri=' + facebookOptions.redirectUri + '&client_secret=' + facebookOptions.clientSecret + '&code=' + authCode;
$.ajax({
type: 'GET',
url: url,
success: function(data) {
var response = data;
// parse 'access_token' from the response
response = response.split('&');
accessToken = response[0].split('=');
accessToken = accessToken[1];
// get authenticated users' info for future use
getUserInfo();
},
error: function(data) {
alert('Error getting access_token: ' + data.responseText);
return false;
}
});
} catch (e) {
alert('Error in getAccessToken: ' + e);
}
}
// get users info (we're grabbing their full name for this sample)
function getUserInfo() {
try {
var url = 'https://graph.facebook.com/me?access_token=' + accessToken;
$.ajax({
type: 'GET',
url: url,
dataType: 'json',
success: function(data) {
// data.name = users full name
showMessage('Hello ' + data.name + '!');
$('#buttonSetup').hide();
$('#afterAuth').show();
},
error: function(data) {
alert('Error getting users info: ' + data.responseText);
return false;
}
});
} catch (e) {
alert('Error in getUserInfo: ' + e);
}
}
// update the users status
function postToService() {
try {
var status = $('#inputBox').val();
if (status === '' || status === 'enter your status...') {
showMessage('You didn\'t enter anything to post :(');
return false;
} else {
showMessage('Updating status...');
var url = 'https://graph.facebook.com/me/feed?message=' + status + '&access_token=' + accessToken;
$.ajax({
type: 'POST',
url: url,
dataType: 'json',
success: function(data) {
showMessage('Status updated!!');
$('#inputBox').val('enter your status...');
// display the updated news feed to the user
setTimeout(function() {
getFeed();
}, 200);
},
error: function(data) {
alert('Error updating status: ' + data.responseText);
return false;
}
});
}
} catch (e) {
alert('Error in postToService: ' + e);
}
}
// get users news feed
function getFeed() {
try {
showMessage('Getting news feed...');
var url = 'https://graph.facebook.com/me/feed?access_token=' + accessToken;
$.ajax({
type: 'GET',
url: url,
dataType: 'json',
success: function(data) {
showMessage('Your news feed...');
var feed = data.data;
// clear the content div, and prepare to add new data to it
$('#content p').remove();
// show the last 4 items from the users news feed
// note: there are several objects that could be posted in a news feed. for simplicity
// we're only showing objects with a 'story' attribute
for (var i = 0; $('#content p').size() < 4; i++) {
if (typeof feed[i].story !== 'undefined') {
$('#content').append('<p>' + feed[i].story + '</p>');
}
}
// display the feed, after it's been parsed
$('#content').fadeIn();
},
error: function(data) {
alert('Error loading news feed: ' + data.responseText);
return false;
}
});
} catch (e) {
alert('Error in getFeed: ' + e);
}
}
// helper function for displaying a message to the user
function showMessage(msg) {
try {
if (!$('#message').is(':visible')) {
$('#message').show();
}
setTimeout(function() {
$('#message').html(msg);
}, 500);
setTimeout(function() {
$('#message').fadeOut(500, function() {
$('#message').html('');
});
}, 8000);
} catch (e) {
alert('Error in showMessage: ' + e);
}
}
the php redirect file on my web server is this:
<?php
$queryString = $_SERVER['QUERY_STRING'];
header("location: local:///index.html" . $queryString);
?>
I am not sure whether the problem is with the authorization in oauth.js or in the local redirect php file.
I have just updates all the OAuth samples to work in the newest SDK.
Get the updated sample from: https://github.com/blackberry/BB10-WebWorks-Samples
The problem is that the initApp function wasn't being executed. This is because the webworksready event wasn't being fired. Now that the samples have been update to reflect the new way of including the webworks.js file, this should no longer be an issue.

facebook login not working

I had implemented facebook login in my project using javascript code. It was working fine, but now it is not working.The login popup was also not working.
code is here
<fb:login-button autologoutlink="true" perms="email,user_birthday,status_update,publish_stream"></fb:login-button>
i changed perms to scope.the popup came but the script problem is still there.
script code used:
<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({appId: 'APPID', 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) {
fqlQuery();//fqlquery function
});
}
function logout(){
document.getElementById('login').style.display = "none";
}
function fqlQuery(){
FB.api('/me', function(response) {
var query = FB.Data.query('select name, hometown_location, sex, pic_square from user where uid={0}', response.id);
query.wait(function(rows) {
document.getElementById('name').innerHTML =
'Your name: ' + rows[0].name + "<br />" +
'<img src="' + rows[0].pic_square + '" alt="" />' + "<br />";
});
});
}
is there any other way to correct the problem?? please help....
I think you're missing the APP ID from the querystring when loading the facebook javascript SDK. Per https://developers.facebook.com/docs/reference/plugins/login/ they want it there for some reason
<div id="fb-root"></div>
<script>(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#xfbml=1&appId=APP_ID";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
Also I noted that your login button HTML doesn't have correct attributes. Per the documentation, show-faces, width, max-rows, and scope are the only valid parameters.

Categories