I am trying to name of the members of close friends list:
FB.api("/me/friendlists/close_friends?fields=members.fields(name)")
but it is not working.
FB.api("/me/friendlists/close_friends?fields=members")
gives me complete members object with following structure
Object {data: Array[1], paging: Object}
data: Array[1]
0: Object
id: "10150338266588525"
members: Object
data: Array[1]
0: Object
id: "812290716"
name: "My Friend"
To read a FriendList, issue an HTTP GET request to /FRIENDLIST_ID with
the read_friendlists permission.
FB.api("/FRIENDLIST_ID?fields=name,members.fields(name)")
You can also call like this, this returns name and id ( default), just ignore the userid, if you dont want.
FB.api("friendlists/close_friends?fields=members.fields(name)")
Try FB Graph API Explorer, Hope this helps.
Related
I've got two models: Note and Profile. Note contains foreign key of connected profile as you can see below.
Note: {
profile_id: String,
date: String,
content: String,
}
Profile: {
id: String,
name: String,
profilePicture: String
}
I want to get all notes and also name and profile picture of note.
In this situation should I:
get all notes and all profiles and then join them locally in for loop,
get all notes and then in for loop ask DB for name and picture of matching profile,
other option
Which way is recomended?
Take a look at mongoose's Populate. You can declare a Schema property with type: Schema.Types.ObjectId, ref: 'Profile'. When you run a Query you can .populate() this field with the corresponding document.
I have three JSON files "Friends" and followers.
friends: contains the information about friends and their tweets
followers: contains information about followers and their tweets
tweets: contains all tweets
I want to extract the following info and store it in a MongoDB collection named "friends"
id_str,
name,
description,
favorites_count,
followers_count,
friends_count,
language,
location,
screen_name,
url,
utc_offset
the tricky part for me is the "Each user (friend or follower) must contain its tweets in a new field tweet"
any suggestions on how to achieve that?
Here what I am doing at the moment:
JsonSlurper slurper = new JsonSlurper()
def friends = slurper.parseText(new File('./friends.json').text)
def followers = slurper.parseText(new File('./followers.json').text)
def tweets = slurper.parseText(new File('./tweets.json').text)
friends.users.forEach{ fr ->
def frnds = mongo.friends << [
[
id_str: fr.id_str,
name: fr.name,
description: fr.description,
favorites_count: fr.favourite_count,
followers_count: fr.followers_count,
friends_count: fr.friends_count,
language: fr.language,
location: fr.location,
screen_name: fr.screen_name,
url: fr.url,
utc_offset: fr.utc_offset
]
]
}
Error: Exception in thread "main" groovy.lang.MissingPropertyException: No such property: friends for class
you can use mongoose population method to display/store object of your user.
for example
followers:[{
type:Schema.Types.ObjectId,
ref:'follower'
}]
you can use reference user id and store in array just id will going to store in followers array and you can populate all ids in to object, so try to use ref in mongoose model.
this might look little bit confusing but consider looking this at mongoose populate method
and also take a look at this video tutorial.
hope it helped!
As the Graph API documentation says, the /comment retreives a Comment Object, which contains a from attribute, which represents the user that made the comment. By default, that from attribute comes with an id and a name.
Although I know I can get the profile image with the id, it will depend on the access_token as the way would be like this:
return 'https://graph.facebook.com/' + id + '/picture?type=large&access_token=' + accessToken;
How can I do to get the profile img of the commentator without depending on the access_token? Because when the API retreives a User object, in the fields object, you can request { fields: "id,name,picture }. But how can i do to ask for the picture to the from attribute that comes in the Comment object? As this is not allowed { fields: "id,name,from.picture }
You should be able to ask for second level attributes
https://developers.facebook.com/docs/graph-api/using-graph-api/#fieldexpansion
$ fbapi '/v2.6/me/photos?fields=from{picture}' | jq '.data[0]'
{
"from": {
"picture": "https://scontent.xx.fbcdn.net/v/t1.0-1/xxxx/p50x50/xxxx.jpg",
"id": "9999999999"
},
"id": "000000000"
}
What is a correct rest way of getting a resource ID by a field, for example a name. Take a look at the following operations:
GET /users/mike-thomas
GET /users/rick-astley
I don't want to use these operations at my API end, instead I want to write an API operation that will get me the ID when submitting a field (name in the case of users) for example:
GET /users/id-by-field
Submitted data:
{
"fullName": "Mike Thomas"
}
Return data:
{
"data": {
"id": "123456789012345678901234"
}
}
What you want is known as an algorithmic URL where the parameters for the algorithm are passed as URL parameters:
GET /users?name="Mike Thomas"
Advantages are that you are using the "root" resource (users) and the search parameters are easily extended without having to change anything in the routing. For example:
GET /users?text="Mike"&year=1962&gender=M
where text would be searched for in more than just the name.
The resultant data would be a list of users and could return more than the identification of those users. Unless fullName uniquely identifies users, that is what you need to allow for anyway. And of course the list could contain a single user if the parameters uniquely identified that user.
{
users: [
{
id: "123456789012345678901234",
fullName: "Mike Thomas",
dateJoined: 19620228
}
, {
id: "234567890123456789012345"
fullName: "Rick Astley",
dateJoined: 19620227
}
]
}
I created the following schema (coffeescript):
user_schema = new app.db.schema(
username: String
email: String
password: String
account:
plan:
type: String
default: "Free"
enum: ["Free", "Bronze", "Silver", "Gold"]
comments: [
title: String
message: String
date_added: Date
]
)
I could have probably created 2 more schemas here (account and comment) but I know each user has one account associated and each account has maximum 100 comments so I like the idea of having it all inside a single document. It's not making sense I know (user/account/comments) but I'm just familiarizing myself to noSql and rich documents so it's just a test.
My question is about saving a new comment for a given account and validating them. I can validate a user email by doing this (which works btw):
user_schema.path("email").validate((value, respond)->
respond v.check(value).isEmail()
, "Invalid email address")
...but how would I validate a comment? How do I save a new comment under a given user.account.comments array? Comments are not required by default but if a new comment is added I want to validate that the title and message is required let's say.
Is this type of nesting normal or I have to create separate models and reference them? I read a lot about embedding vs linking and I feel like this would make for an embed?
You put the validation attributes right in the schema definition of the embedded object:
comments: [
title:
type: String
required: true
message:
type: String
required: true
date_added: Date
]