I trying to get my immediate family data from facebook using FQL. I run this statement:
SELECT first_name, middle_name, last_name, birthday_date
from user
where uid IN (SELECT uid
FROM family
WHERE profile_id = me()
and (relationship = 'brother'
or relationship = 'sister'
or relationship = 'father'
or relationship = 'mother'
or relationship = 'son'
or relationship = 'daughter'
or relationship = 'wife'
or relationship = 'husband'))
But I want to have also the relatioship in the data. It gives me only first_name, middle_name, last_name, birthday_date
You have to do a to get this data, you need to do an FQL multi-query:
{"my_family": "SELECT uid, relationship FROM family WHERE profile_id = me() AND
(relationship = 'brother' OR ...)".
"family_details": "SELECT first_name, middle_name, last_name, birthday_date FROM
user WHERE uid IN (SELECT uid FROM #my_family)"}
You'll need to join the two result objects together on uid in your script.
Do you need to use FQL? There is now a nested field Graph API syntax that gets you exactly what you need in one go:
https://graph.facebook.com/me?fields=id,name,family.fields(first_name,middle_name,last_name,birthday)
The result is then a nested JSON object with the relationship field as you require - something like:
{
"id": "738229837",
"name": "James Pearce",
"family": {
"data": [
{
"first_name": "Bob",
"last_name": "Pearce",
"birthday": "09/21/1965",
"id": "12345",
"relationship": "cousin"
},
{
"first_name": "Clara",
"last_name": "Pearce",
"birthday": "12/08",
"id": "67890",
"relationship": "mother"
}
...
],
"paging": {
"next": "https://graph.facebook.com/..."
}
}
}
Hope that helps. Have fun.
Related
I'm very new to NoSql databases, and I just want to ask you an easy question about the use of sembast! I'm developing a very simple app with flutter, and I want to get the object inside the array "list" with the "name" equal to 1.
{
"id": 12345,
"list": [{
"name": 1,
"element": [{
"nameItem": "a"
}, {
"nameItem": "b"
}]
}, {
"name": 2,
"element": []
}, {
"name": 3,
"element": []
}]
}
So I want to make a query that retrieves me this information:
{
"name": 1,
"element": [{
"nameItem": "a"
}, {
"nameItem": "b"
}]
}
I've written this code, but it doesn't work: I don't understand how to make a query with a subtag as a key in the json tree.
Future<List<ElementList>> getElementFromList(int name) async{
final finder = Finder(filter: Filter.equals("name", name));
final recordSnapshot = await _elementList.find(await _db, finder: finder);
return recordSnapshot.map((snapshot){
final elementObj = ElementList.fromJson(snapshot.value);
return elementObj;
}).toList();
}
this returns me []. How can I solve the problem?
Thank you in advance!
Sembast queries allow to filter records, not part of a record. If the object you mention is a whole record, you can:
use custom filter to perform the lookup yourself for each record in the database (checking each item in the list field`)
when a record is retrieved, extract the item (doing a similar Map/List manipulation)
See an issue with a complex filtering
I want to create a chat support app model. I have only 1 agent and many requesting users asking queries. Each user can have multiple conversations with the agent (assume it like a whatsapp group having only 2 members, a user and that agent).
So I create a data structure like:
Conversation
-uId
-status
-conversationTitle
and for Messages,
Message
-conversationId
-message
-from //0 mean it from me to my friend and 1 for a message from my friend to me
-timestamp
Basic structure will be like:
Conversation1:{ "uId": "1", "status":0, "conversationTitle": "First conversation"},
Conversation2:{ "uId": "2", "status":0, "conversationTitle": "Second conversation"},
Conversation1:{ "uId": "1", "status":0, "conversationTitle": "Third conversation"}
and for messages:
Message1: {"conversationId": "Conversation1", "message": "Hello there 1!", "from":0, "timestamp":******** },
Message2: {"conversationId": "Conversation1", "message": "Hello there 2!", "from":0, "timestamp":******** },
Message3: {"conversationId": "Conversation2", "message": "Hello there 3!", "from":0, "timestamp":******** },
Message4: {"conversationId": "Conversation3", "message": "Hello there 4!", "from":0, "timestamp":******** },
As you can see Message 1 and 2 belong to Conversation 1 which in turn b belong to User 1 with uID 1.
I want all conversation that is happening with User 1 (uId: 1) and User 2 (uID: 2) must not be able to see conversations of 1.
I wrote security as:
"conversations":{
"$uid":{
".read": "data.child('uId').val() == auth.uid",
".write":"auth != null && newData.child('uId').val() == auth.uid"
}
}
and then in Android:
FirebaseDatabase database = FirebaseDatabase.getInstance();
Query conversationsRef = database.getReference("conversations");
FirebaseRecyclerAdapter<Conversation, ConversationHolder> binderData = new FirebaseRecyclerAdapter<Conversation, ConversationHolder>(Conversation.class, R.layout.item_butler_converastions, ConversationHolder.class, conversationsRef) {
#Override
public void populateViewHolder(ConversationHolder chatMessageViewHolder, Conversation chatMessage, int position) {
chatMessageViewHolder.setName(chatMessage.getTitle());
}
#Override
protected void onCancelled(DatabaseError error) {
super.onCancelled(error);
}
};
When I do this I get permission error. I want to retrieve all conversation belonging to User 1.
I also tried using:
Query conversationsRef = database.getReference("conversations").orderByChild("uId").equalTo(mAuth.getCurrentUser().getUid());
but didn't work. Thanks in advance.
Is it possible to get a Facebook user's name from their Facebook Id number with a graph call?
If so, does anyone know the call?
For example you can get a user's picture by making the following call
"http://graph.facebook.com/" + someUserId + "/picture"
Something like:
String response = facebook.request(userId);
JSONObject json = Util.parseJson(response);
String name = json.getString("name");
String username = json.getString("username");
Simply querying the Graph API with the user_id should be enough to get the name of the user -
http://graph.facebook.com/4
>>
{
"id": "4",
"name": "Mark Zuckerberg",
"first_name": "Mark",
"last_name": "Zuckerberg",
"link": "https://www.facebook.com/zuck",
"username": "zuck",
"gender": "male",
"locale": "en_US",
"updated_time": "2012-05-20T01:29:18+0000",
"type": "user"
}
You could drill down even more by adding a filter for the name field -
https://graph.facebook.com/4?fields=name
>>
{
"name": "Mark Zuckerberg",
"id": "4",
"type": "user"
}
https://graph.facebook.com/UserID.
eg:
https://graph.facebook.com/19292868552
I am having a few problems getting Facebook data to parse properly.
I am working on implementing part of an application to allow a user to select and use one of their own facebook photos within the app. I have gotten the facebook login/logout code working and I am currently getting the token (once logged in) in order to gather the users Album information. The permission set is also working nicely, however I am now stuck at trying to get the JSON information to parse correctly. Here is a sample snippet of the information I need to parse:
"data": [
{
"id": "3486732467234",
"from": {
"name": "Persons Name",
"id": "Persons ID"
},
"name": "Vacation",
"location": "City",
"link": "https://www.facebook.com/album.php?fbid=434235&id=324343&aid=2430",
"cover_photo": "3489234432",
"privacy": "everyone",
"count": 60,
"type": "normal",
"created_time": "2007-06-03T23:01:16+0000",
"updated_time": "2011-03-18T19:46:43+0000",
"can_upload": true
},
{
"id": "4043544665",
"from": {
"name": "Persons Name",
"id": "Persons ID"
},
"name": "Vacation 2",
"location": "City",
"link": "https://www.facebook.com/album.php?fbid=4043434665&id=508154335&aid=2555",
"cover_photo": "5434543",
"privacy": "everyone",
"count": 60,
"type": "normal",
"created_time": "2007-06-03T22:53:03+0000",
"updated_time": "2011-03-18T19:45:55+0000",
"can_upload": true
}],
...more paging JSON information ...}}
I need to be able to pull the album information in order to display the photo album names in a list (and use the ID in another query). Once I can get the albums to show, I would then use those IDs to perform another query to get the photos from that album. Again I can also get that information back, I am just not sure how to properly parse it.
Any useful tips that someone might have in being able to parse this into a listview would be greatly appreciated.
I need to target pulling the first ID and the Album name ("id": "3486732467234" and "name": "Vacation" from the first listing)
why don't you try with the json classes...
something like this:
jsonObject = new JSONObject(your_data);
jArray = jsonObject.getJSONArray("data");
for(int i =0;i<jArray.length();i++){
String name= jArray.getJSONObject(i).getString("name");
String location= jArray.getJSONObject(i).getString("location");
etc.
The new Android Facebook SDK 3.0 returns a Response object in the Response.Callback() listener when making Graph API calls. This response object can be used to create a GraphObject which can be used to get a JSON...ex:
Request graphRequest = Request.newGraphPathRequest(session, graphRequestString, new Request.Callback() {
#Override
public void onCompleted(Response response) {
//Create the GraphObject from the response
GraphObject responseGraphObject = response.getGraphObject();
//Create the JSON object
JSONObject json = responseGraphObject.getInnerJSONObject();
}
});
Coming from SQL background and watching tutorials, I am trying to do a model in Firestore to understand how things work. I basically wants model a situation where user has multiple lists and every list has his friends ( to display names of friends). Does the below make sense?
Users
"john#xyz.com"
-Name: John Smith
"celina#xyz.com"
- Name: Celina West
"dan#xyz.com"
- Name: Dan Nelson
Lists
"john#xyz.com"
List_Titles
"List 1"
- <AutoGenId>: Celina West
- <AutoGenId>: Dan Nelson
anything with "-" is a field, anything with bracket it Document and anything without prefixes is collection.
One issue I find here, is that lets say a user updates his/her name. Then I have to go not to only Users Collection but through every subcollection List to look for that person and update name. I thought about using email ID instead of name but then that goes against the "structure the nosql db as you view it" way. Plus then everytime I have to hit the Users tables in a seperate call for every Id to query the name.
Is my assumption correct?
Thanks
Snake, there is no perfect database structure. You need to model your database so you can query very easily later, when you need to do CRUD operations. In one of my tutorials, I have explained step by step how can we structure a Firestore database which holds users, lists and products.
Please see the below database structure that can help achieve what you want.
{
"users": {
"appfirstuser#gmail.com": {
"tokenId": "eGVzwv7Y...",
"userEmail": "appfirstuser#gmail.com",
"userName": "First User"
},
"appseconduser#gmail,com": {
"tokenId": "cc8Uhriu...",
"userEmail": "appseconduser#gmail.com",
"userName": "Second User"
}
},
"shoppingLists": {
"appfirstuser#gmail.com": {
"userShoppingLists": {
"3Oe37QdcHXSohL2dnNlX": {
"createdBy": "First User",
"date": "February 3, 2018 at 2:56:31 PM UTC+2",
"shoppingListId": "3Oe37QdcHXSohL2dnNlX",
"shoppingListName": "Pharmacy"
},
" WovuleVbTZdql68gXk84": {
"createdBy": "First User",
"date": "February 3, 2018 at 2:56:20 PM UTC+2",
"shoppingListId": "WovuleVbTZdql68gXk84",
"shoppingListName": "Grocery"
}
}
}
},
"products": {
"WovuleVbTZdql68gXk84": {
"shoppingListProducts": {
"8vinaHJyjG4JqFH33YE7": {
"productId": "8vinaHJyjG4JqFH33YE7",
"productName": "Milk"
},
"JALygtedMHWQcdEoSnPM": {
"productId": "JALygtedMHWQcdEoSnPM",
"productName": "Eggs"
},
"WFkJMWZSnhJU9iwGeoOi": {
"productId": "WFkJMWZSnhJU9iwGeoOi",
"productName": "Bacon"
}
}
}
}
}
Using a database structure that looks like this, you'll be abte to create, read, update and delete records very easily.