So I am trying to find some user information from a user. However, I can only get those which are in public_profile and "simple types" like first_name, gender etc. However, I cannot get age_range, or user_relationships status or current locations. I am using the snippet,
FB.api('/me', {fields: 'name,first_name,last_name,email,birthday,age_range'},
function(response) {
...});
everytime I try getting the age_range, it just says [object Object]. But I can get the name and birthday just fine. How should I fix this.
My entire code:-
function checkLoginState() {
FB.login(function (response) {
if (response.status == 'connected') {
FB.api('/me', {fields: 'name,first_name,last_name,email,birthday,age_range'},
function(response){
document.getElementById('status').innerHTML =response.first_name+
' '+ response.last_name+ ' ' + response.email+ ' ' +response.birthday+ ' ' +
response.age_range;
});
}, { scope: "public_profile,email" });
}
Thank you in advance!
age_range is an object, it looks like this in the result:
"age_range": {
"min": 21
},
Try with console.log(response.age_range.min), for example.
Not sure what you mean with the other things, you are not even asking for the hometown or other stuff.
Related
I am using the Moxtra JavaScript SDK to implement the timeline functionality in my app.
I want to create a central binder for my user groups and got everything working except the inviting of another of my users to a existing binder.
function getTimeline(access_token, binderID) {
var options = {
access_token: access_token,
binder_id: binderID,
iframe: true,
tagid4iframe: "container",
iframewidth: "920px",
iframeheight: "650px",
autostart_meet: true,
autostart_note: true,
extension: {"show_dialogs": {"meet_invite": true}},
start_timeline: function (event) {
alert("Timeline started session Id: " + event.session_id + " binder id: " + event.binder_id);
},
view_binder: function (event) {
alert("Binder switched session Id: " + event.session_id + " binder id: " + event.binder_id);
},
invite_member: function (event) {
var userID = UNIQUEUSERID
alert("Invite member into binder Id: " + event.binder_id);
console.log(Moxtra.baseUrl + "/" + event.binder_id + "/inviteuser");
var postData = {
"users": [
{
"user": {
"unique_id": userID
}
}
],
"message": "Custom message to join this conversation..."
};
$.ajax("https://api.moxtra.com/v1/" + event.binder_id + "/inviteuser", {
type: 'POST',
data: postData,
contentType: 'application/json',
crossDomain: true,
success: function (data) {
console.log(data);
}
});
},
start_meet: function (event) {
alert("Meet started session key: " + event.session_key + " session id: " + event.session_id);
},
end_meet: function (event) {
alert("Meet end event");
},
save_meet: function (event) {
alert("Meet saved on binder: " + event.binder_id);
},
start_note: function (event) {
alert("session key: " + event.session_key + " session id: " + event.session_id);
},
save_note: function (event) {
alert("Note saved on binder: " + event.destination_binder_id);
},
cancel_note: function (event) {
alert("Note cancelled");
},
error: function (event) {
alert("Timeline error code: " + event.error_code + " error message: " + event.error_message);
}
};
Moxtra.timeline(options);
}
as you can see the getTimeline request handles the invite_member event, there is no build in invite user to chat/binder so I can't use that.
Seeming that the SDK calls the REST API I am using that myself to add the invite user functionality. But when I test the request with their API console I get a error saying that the group is not found.
I assign the users to the same group so that shouldn't be the issue and tried to add a user via my unique-id and the moxtra unique-id. What am I doing wrong? Or what other options do I have?
I assume the binder that you are trying to add users (using their unique id) was also created by an user who got created in Moxtra using unique_id method. In that case using the REST API to add team member is the right approach to add additional users to the binder.
When you use the API console, you will be using the access token generated through your moxtra email account. It cannot be used with the binder that you created through the unique_id method.
Based on the error that you mentioned above it looks like either the user who you are trying to add or the user who created the binder are not in the same group. Please make sure both the users are provisioned using the same SSO method.
After spend 6 hours trying different approaches to my problem, I always get the same error and can't figure out why.
The problem is simple to understand: I have 10 users saved in Appcelerator Titanium ACS and I want to create 10 records, one for each user.
The stuff must be easy: all users have the same pass, so I only need to login with each one, create the object as the user and, thats all!! (In ACS, the objects are owned (and have user_id assigned automatically) by the user who creates them).
To manage async, I use functions with callback to wait till the end.
var Cloud = require('ti.cloud');
function createObject(value, onComplete) {
Cloud.Objects.create({
classname: 'MyObj',
session_id: Cloud.sessionId,
fields: {
value: value
}
}, function(data) {
if (data.success) {
Ti.API.info('New value: user [' + data.Scores[0].user_id + '] - value: ' + data.Scores[0].value);
onComplete(true);
} else {
Ti.API.info('Error: ' + data.message);
onComplete(false);
}
});
}
function login(user, onComplete) {
Cloud.Users.login({
login: user.username,
password: '1234'
}, function(e) {
if (e.success) {
createObject(20, function(cb) {
onComplete(true);
});
} else {
Ti.API.warn('Error login user: ' + e.message);
onComplete(false);
}
});
}
// Get target users
Cloud.Users.query({
response_json_depth: 1
}, function(data) {
if (data.success) {
_.each(data.users, function(user) {
login(user, function(cb) {
Ti.API.warn("user: " + user.username);
});
});
}
});
Well, my results are always the same:
Ti.API.warn('user: ' + user.username); shows the right users name (one by one), but Ti.API.info('New value: user [' + data.Scores[0].user_id + '] - value: ' + data.Scores[0].value); shows always the same user, meaning that all the values are saved for the same user (checked in DB, are all the same user), instead of 1 value per user.
I also tried to use async in the _.each command, but with the same results.
Where is the problem? I think I'm waiting in _.each user for the login, and the login must wait to finish the createObject, but seems I'm doing something wrong.
And here the exit. No sense for me...:
New value: user [54cb62cf18beba0935422a35] - value: 20
user: krusty
New value: user [54cb62cf18beba0935422a35] - value: 20
user: apu
New value: user [54cb62cf18beba0935422a35] - value: 20
user: ned
Note: the user_id saved for all calls correspond to user NED (the last)
It was a bug in ACS. Anyway, it doesn't matters currently, because was fixed 5 years ago.
I try to get the image upload to facebook working... Unfortunately, the facebook graph API always returns the following error:
{ error: Objectcode: 324, message: "(#324) Requires upload file", type: "OAuthException" }
It seems that the picture data is not transfered correctly. The facebook docs tell me to use a multipart/form-data upload. (See here > Publishing)
I am using angular-easyfb as a wrapper for the faceebook sdk. What's the easiest way to get this thing working? My current code is:
var sharePhoto = function() {
ezfb.api("/me/photos",
"POST",
{
"source": content,
"message": "This is a test Photo"
},
function (response) {
console.log("shared", response);
if (response && !response.error) {
/* handle the result */
}
});
};
ezfb.getLoginStatus(function(response) {
if(response.status === 'connected') {
console.log("already conntected", response);
sharePhoto();
} else {
ezfb.login(function(response) {
// Do something with response.
console.log("FB",response);
sharePhoto();
}, {scope: 'public_profile,email,user_photos,publish_actions'});
}
});
The console-log is:
already conntected {status: "connected", authResponse: Object}
shared {error: {code: 324, message: "(#324) Requires upload file", type: "OAuthException"}}
My questions are:
Whats the expected format of my variable content? How do I need to
encode it?
Do I have to manipulate the request Headers of the request? How?
Thanks a lot for your help!
Edit: Console-Log added
This question already has an answer here:
(#200) The user hasn't authorized the application to perform this action
(1 answer)
Closed 8 years ago.
got error when i want to post text in facebook wall .
this is my code
function logout() {
FB.logout(function(response) {
alert('logged out');
});
}
// i am able to login successful . using this method .
function login() {
FB.login(function(response) {
if (response.authResponse) {
var access_token = FB.getAuthResponse()['accessToken'];
alert('Access Token = ' + access_token);
alert("Welcome! Fetching your information.... ");
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Good to see you, ' + response.name + '.');
});
} else {
alert("User cancelled login or did not fully authorize.");
console.log('User cancelled login or did not fully authorize.');
}
},{
scope: 'publish_actions',
return_scopes: true
});
}
// here i call this method to post the text in FB wall . and i am getting status logged in a but i got error .
function SubmitPost() {
FB.getLoginStatus(function(response) {
if (response.status == 'connected') {
alert('logged in');
try {
var wallPost = {
message: "post in fb" ,
picture: '',
link: '',
name: 'test app posted in your wall',
caption: '',
description: ('Test description')
};
FB.api('/me/feed', 'post', wallPost, function (response) {
if (!response || response.error) {
/*action*/
alert('Message could not be Posted.');
alert(response.error.message);
console.log(response.error.message);
} else {
/*action*/
alert('Message Posted successfully.');
}
});
}
catch (err) { alert('SubmitPost: ' + err);
}
} else {
alert('not logged in');
}
});
}
Please check your host URL matches with the URL given in the Facebook app "Website URL". Both should be exactly same.
If your are not added in facebook Website URL which reside under your App setting , then you can create this by hitting to "Add Platform" .
Steps to get website URL for the Facebook application:
1] If you are not created facebook app , To create Goto
https://developers.facebook.com/?ref=pf
2] Select Apps -> Create a new app
3] Fill the app details in the popup. Click on Create App
4] You will be redirected to dashboard page of your newly created application.
[ Note down the AppID]
5] Then click on "Settings" present at left side and then click on Add Platform
6] Choose "Website" from the popup menu.
7] Now you can find 2 fields : Site URL and Mobile Site URL.
Here you should fill your website URL where your are calling facebook SDK.
I'm using jquery.couchdb.js to query my CouchDB database. The view I want to query has both map and reduce functions within. When sending the basic query as shown below:
$(document).ready(function() {
view_name = db_name+'/jobs_by_mod_stat'
options = {'group': 'true' , 'reduce': 'true' };
mod_stat = {};
$db.view(view_name , {
success: function(data) {
console.log(data)
for (i in data.rows) {
console.log(data.rows[i].value);
}
},
error: function(e) {
alert('Error loading from database: ' + e);
}
});
});
I see a sensible log for the data, indicating the query has been successful. However, changing the line:
$db.view(view_name , {
To
$db.view(view_name , options, {
I don't get a success outcome from the Ajax query, but an error message is not shown either. Firebug shows the query being sent, and the JSON data returned looks sensible:
{"rows":[
{"key":["template","completed"],"value":2},
{"key":["template","running"],"value":2},
{"key":["template","waiting"],"value":6}
]}
But the success function is not entered. Any ideas why I'm seeing this behaviour, I did wonder if it's a bug in jquery.couch.js (I have couchdb 1.1.0).
Cheers.
I've had a bit of trouble myself with the list function, until I went and looked through the source code of jquery.couch.js (the online documentation I found at http://bradley-holt.com/2011/07/couchdb-jquery-plugin-reference/ seems to be outdated).
Basically, the parameters for view and list are different, the list having an extra parameter for the options, instead of having everything under the same parameter as with views.
View:
$.couch.db('yourdb').view('couchapp/' + viewName, {
keys: ['keys here'],
success: function (data) {
}
});
List:
$.couch.db('yourdb').list('couchapp/' + listName, viewName, {
keys: ['keys here']
}, {
success: function (data) {
}
});