Fetching list of user's friends for website - facebook-javascript-sdk

I have implemented Fb login for my website. Also for the Fb page of my app inside approved items it shows - user_friends
Provides access to a person's list of friends that also use your app. This permission is approved by default.
How can I get the list of friends of the user who is there on my app ?
Also When I try to do this --
FB.api(
"/me/friends",
function (response) {
if (response && response.data){
alert(response.data);
} else {
console.log('Something goes wrong', response);
}
}
);
I get no response.
Thanks,
Newbie

First, you need to include and initialize the JavaScript SDK: https://developers.facebook.com/docs/javascript/quickstart/v2.2
Then, you need to authorize the user: https://developers.facebook.com/docs/reference/javascript/FB.login/v2.0
(donĀ“t forget to use the scope parameter with the "user_friends" permission)
After that, you can call FB.api('/me/friends'... to get the friends of the user who authorized the App too.
You can also test /me/friends in the API Explorer, just select the correct App: https://developers.facebook.com/tools/explorer/?method=GET&path=me%2Ffriends&version=v2.2

Related

Facebook js api - "unsupported get request" error

I'm trying to get some (I think allowed) information in my app. I have an access token that has the following info:
App ID: <my app id> : iHOUSEListingPoster - Test 001
Type: User
App-Scoped User ID: <user id> : Joe Webb
Valid: True
Scopes: email, pages_show_list, pages_read_engagement, pages_manage_posts, public_profile
I'm trying this:
FB.api( "/me",
"GET",
{fields: 'name'},
function(get_fb_info_response) {
console.log("Here: ", get_fb_info_response
});
And getting this error:
"Unsupported get request. Object with ID 'me' does not exist, cannot be loaded due to missing permissions, or does not support this operation"
I have tried with both "/me" and "/me/". And while I want name, picture and email, I tried limiting it to just name, and still. What am I missing here?
Try this:
FB.api('/me?fields=name', function(response) {
console.log('me', response);
});
I'm not sure if api function from FB does have this signature you're using.
Edit
After searching at Facebook docs, found that the signature you were using is valid as well. Then, I went to do some tests here. And I was able to reproduce the same error you have mentioned when calling the function like this:
FB.api("/<123>/", "GET", { fields: 'name' }, function(response) {
console.log('response', response);
});
To fix it, you need to remove < and >, for example:
FB.api("/123/", "GET", { fields: 'name' }, function(response) {
console.log('response', response);
});
Calling /me and /me/ endpoint returned no error in my test.
In this screenshot you can see the tests I have run directly at my browser's console.
Ok, I finally figured out what the problem is/was here (sheepish face). We have a couple of Facebook accounts here at the company. One is the container for my app and it's test app, the other is a more general company account. I was logged into the general company account. When I tried my app, it grabbed some random app from that account, which wasn't the app that matched the access token (which I think is possible wrong on Facebook's part), therefore this error was thrown.
Once I logged into the correct Facebook account, all works as expected.

Cognito unable to signup users that have unconfirmed status already

A Cognito User Pool is configured for the users to use their "email address" to sign up and sign in.
If a user signs up with the email of someone else then that email will get stuck in UNCONFIRMED state and the owner will not be able to use it appropriately.
Having said that let me provide an example with the following scenario:
User signs in with an email address the user doesn't own, let's say it is someone#mail.com. In this step (registration form) some more data is sent like organization name, and user full name.
Verification code is sent to the email
Now the user that owns someone#email.com wants to create an account (maybe some days in the future), so he goes and fills the registration form but an error is thrown by cognito {"__type":"UsernameExistsException","message":"An account with the given email already exists."}
Thinks to consider:
* If the email already exists but is in unconfirmed state then provide the user the option to resend the link. This option is not optimal because additional data might be already in the user profile as the 1st step exemplifies.
* A custom lambda can be done to delete the unconfirmed user before signup or as a maintenance process every day, but I am not sure if this is the best approach.
There is also this configuration under Policies in cognito consol: "How quickly should user accounts created by administrators expire if not used?", but as he name implies this setting will only apply to users if they are invited by admins.
Is there a proper solution for this predicament?
Amazon Cognito has provided pre-signup triggers for these functionality and auto signup also.Your thought is the same way as i have implemented that according to the cognito documentations.
Here I am using the amplify/cli which is the toolchain for my development purpose hence the lambda function used in the trigger is as below:
`
"use strict";
console.log("Loading function");
var AWS = require("aws-sdk"),
uuid = require("uuid");
var cognitoIdentityServiceProvider = new AWS.CognitoIdentityServiceProvider();
exports.handler = (event, context, callback) => {
const modifiedEvent = event;
// check that we're acting on the right trigger
if (event.triggerSource === "PreSignUp_SignUp") {
var params = {
UserPoolId: event.userPoolId,
Username: event.userName
};
cognitoIdentityServiceProvider.adminGetUser(params, function(err, data) {
if (err) {
console.log(err, err.stack);
} // an error occurred
else {
console.log("cognito service", data);
if (data.UserStatus == "UNCONFIRMED") {
cognitoIdentityServiceProvider.adminDeleteUser(params, function(
err,
data
) {
if (err) console.log(err, err.stack);
// an error occurred
else console.log("Unconfirmed user delete successful ");
// successful response
});
}
// successful response
}
});
return;
}
// Throw an error if invoked from the wrong trigger
callback('Misconfigured Cognito Trigger '+ event.triggerSource);
};
`
this will actually check and delete if the status is UNCONFIRMED using the aws-sdk methods adminGetUser and adminDeleteUser
hope this will help ;)
I got around this by setting ForceAliasCreation=True. This would allow the real email owner to confirm their account. The draw back is that you end up with 2 users. One CONFIRMED user and another UNCONFIRMED user.
To clean this up, I have a lambda function that calls list-users with filter for unconfirmed user and delete the accounts which were created before a certain period. This function is triggered daily by CloudWatch.
change to confirm from unconfirm:
aws cognito-idp admin-confirm-sign-up \
--user-pool-id %aws_user_pools_web_client_id% \
--username %email_address%

How to get all users by project on Youtrack rest api?

I can't get users by project or by filter on YouTrack REST API;
I wrote the following code:
var login = "mylogin";
var password = "mypassword";
(async function getAllUserByProject(login, password, project) {
var url = ``https://mycompany.myjetbrains.com/hub/api/rest/users?`;
return new Promise((done, fail)=> {
request.get({
url, auth: {user: login, pass: password, sendImmediately: true}
}, (error, body, result)=> {
if (error || !result) {
return fail({
error: JSON.parse(error), result: result ? JSON.parse(result) : null
})
}
console.log(result)
done(JSON.parse(result));
})
})
}
)(login, password, project);
Old question but:
users by project
Use /rest/admin/user?project=<PROJECT_ID>. I tested this on v2017.3 and it works.
Reference: https://www.jetbrains.com/help/youtrack/standalone/GET-Users.html
by filter
As seen in the documentation, the resource url takes the form of /rest/admin/user?{q}&{group}&{role}&{project}&{permission}&{onlineOnly}&{start} where:
q can be part of user login, name, or email
group is the user's groupID
role is the users's role
project see above
permission is one of the user's permissions
onlineOnly get only users which are currently online
start for pagination (page size fixed at 10)
As of YouTrack 2018.3, the old REST API is becoming deprecated in favor of one that allows much more elaborate queries.
With the new API, you can use /hub/api/rest/projectteams/?$top=-1&fields=id to get the full list of ids of all project teams, and, for each of those, /hub/api/rest/projectteams/{project id}/users to get the list of users in a given project team.

How to find access_token expired or not in Onedrive?

In Onedrive I am able to use their Live SDK API and get the Access_token and the filepicker for my users is also working properly.
But, every time a user tries to attach a file I am calling the API to get the Access_token.
Is this a problem, when more number of users try to call this API every time they try to attach the files( did Microsoft has a limit for number of API call).
Also, If i try to use Refresh_token for Access_token using WL.offline_access scope how would my app know the Access_token is expired?
You'll need to add logic to your code to see if the user is already has a session occurring. You can do this this by adding WL.Event.subscribe and checking for "auth.statusChange". If the users status has changed at any point, it will call the function to check the users current status (i.e. connect, notConnected, and unknown) by calling WL.getLoginStatus. WL.getLoginStatus will also return the users session object (access_token, expires_in, etc) if you want to use any values there.
Your code will look something like this.
< script type = "text/javascript" >
WL.Event.subscribe("auth.statusChange", chkStatus);
function chkStatus() {
WL.getLoginStatus(
function(response) {
if (response.status == "connected") {
document.getElementById("info").innerText = "You're signed in";
} else {
WL.login({
"scope": "wl.skydrive_update"
});
}
More info on WL.getLoginStatus can be found at https://msdn.microsoft.com/EN-US/library/hh550842.aspx. I hope that helps.

Getting user data is inconsistent on the php and javascript sdk

I've been developing a facebook application that uses a combination of the php sdk and the javascript sdk. It runs in a tabbed iframe on facebook and is hosted on my own server. I'm using the latest php and javascript sdk files as of now (Sept 06, 2011, 2:50PM). The first inconsistency is in the php sdk when getting the user id. This is my code:
require 'fb_php_sdk/facebook.php';
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
$user = $facebook->getUser();
if ($user) {
$permissions_granted = true;
} else {
$permissions_granted = false;
}
This very frequently returns '0' as the facebook ID, no idea why. Though almost as frequently returns the actual facebook id.
The other issue is with images. I often get images not showing up when calling this url:
<img src="https://graph.facebook.com/' . $uid. '/picture/" />
When I use fql I inconsistently get 'undefined' as a result when performing this query:
FB.api(
{
method: 'fql.query',
query: 'SELECT name,pic FROM user WHERE uid=<? echo $user ?>'
},
function(response)
{
alert(response[0].pic);
}
);
I really don't understand what would cause this inconsistency and it's making bug testing very difficult. If anyone has experienced this kind of behaviour and can point me in the right direction I'd really appreciate it. Thanks!
This very frequently returns '0' as the facebook ID, no idea why. Though almost as frequently returns the actual facebook id.
Of course, because your app needs at least the default permissions. Otherwise you'll get nothing about the user. And same with your images. I bet most time your $uid contains the number zero.
Did you check what facebook returns? It should be something like:
{
"error": {
"type": "OAuthException",
"message": "An active access token must be used to query information about the current user."
}
}
So you need to get permissions of the user to get access to his/her data.
Kind regards,
Jurik