How to Separate the Profile Details - iphone

I try to read education details from face book using JSON in IPhone.
I read all education details from Face book successfully.
But i get the whole details. I want to separate the school, college {PG and UG}. But the node having same name like school. and also the data wil be read first one school, and then read one college, then again read one school and read one college like that. somebody fill one school more than one college. somebody wil fill more than one school and one college, somebody wont fill school or college. some id having same number of schools and college. some id having different number of schools and college. So how to I identify the schools and college details separately. Please if anybody having any idea please share with me.
MY Doubt is how to identify the schools, and college and then print schools and college separately...
My sample output as follows..
"education":
[
{
"school":
{
"id":110402725649312,
"name":"10th class"
},
"year":
{
"id":102356633142124,
"name":"2001"
}
},
{
"school":
{
"id":111983532181734,
"name":"Bsc Maths"
},
"year":
{
"id":146950445337693,
"name":"2006"
},
},
{
"school":
{
"id":115980035092981,
"name":"+2"
},
"year":
{
"id":114786038555902,
"name":"2003"
}
},
{
"school":
{
"id":130814456944277,
"name":"mca"
},
"year":
{
"id":115598488468394,
"name":"2010"
},
}
}]
Thanks to all...

I don't know how to retrieve a school ID from Facebook based on the id field you're getting there, but I'm sure there's a way to traverse their Social Graph structure to find it.
The advice I have for you is: Use the json-framework to convert that into a native NSArray containing NSDictionaries. Then walking that data becomes a ton easier.

Related

Get real-time comments from videos live Facebook-live-api

I'm setting up an endpoint to receive real-time comments from the live streaming video, I follow the steps in this document smoothly: https://developers.facebook.com/docs/graph-api/server-sent-events/endpoints/live-comments/.
There was one person who commented directly on my live streaming video twice, and I also got those 2 comments, but that person's "id" in 2 comments is different. Can anybody explain me on this, and is there any way to fix it.
var source = new EventSource(
'https://streaming-graph.facebook.com/{live-video-id}/live_comments?access_token={access_token}&comment_rate=one_per_two_seconds&fields=from{name,id},message');
source.onmessage = function(event) {
console.log(event.data);
};
response 1:
{ "from": { name: "Joe Commenter", "id": 126577551217199 },"message":
"I like it!" }
response 2:
{ "from": { name: "Joe Commenter", "id": 23567175551752 },"message":
"Great photo!" }
They're two different accounts, probably a bot building a profile to be used for spam later.

MongoDB Get Multiple objects with the same name within objects with different name:

So I can't seem to get the results I want so I'm asking for your kind help on it. Imagine a MongoDB database built for multi-language content, something like this:
"info": {
"en": {
"greetings": {
"hello":"hello",
"goodbye":"goodbye"
},
"directions": {
"left": "left",
"right": "right"
}
},
"pt": {
"greetings": {
"hello":"olá",
"goodbye":"adeus"
},
"directions": {
"left": "esquerda",
"right": "direita"
}
}
}
Now if I want to query in order to get the directions object in both English and Portuguese but not the greetings, how should I do it?
If it helps, my purpose is to subscribe to exactly that content on a meteor app's template, so no need for all other objects within a given language object, just the one I need for any given template.
Thanks in advance!
how about you iterate?
db.collection.find().forEach((language){
some code here
})

Difficulty using `populate` with `groupBy` and `sum` with Waterline query in Sails.js

I have run into a strange problem with the groupBy and sum methods when used with populate. I have a set of associated models: User, Source (books, etc), Recommendation, and Discipline (i.e. academic discipline).
I attempted the following waterline query:
Recommendation.find({
where: {discipline: '5559ea07dfa9bd0499f9f799'},
groupBy: ['source'], sum: ['rating']
}).exec(console.log);
This worked well, returning:
[
{
"source": "5571e72ab50f0c3c49fe19f6",
"rating": 4
},
{
"source": "5571b88c51861950360fac1c",
"rating": 12
}
]
I then tried it with populate on the source because I wanted to have the full source data linked to the each recommendation. So I tried:
Recommendation.find({
where: {discipline: '5559ea07dfa9bd0499f9f799'},
groupBy: ['source'], sum: ['rating']
}).populate('source').exec(console.log);
This yielded something strange:
[
{
"source": {
"type": "book",
"identifiers": [
{
"type": "ISBN_10",
"identifier": "1400823226"
},
{
"type": "ISBN_13",
"identifier": "9781400823222"
}
],
"title": "Patterns for America",
"subtitle": "Modernism and the Concept of Culture",
"publisher": "Princeton University Press",
"year": 1999,
"language": "en",
"categories": [
"Literary Criticism"
],
"abstract": "In recent decades, historians and social theorists have given much thought to the concept of \"culture,\" its origins in Western thought, and its usefulness for social analysis. In this book, Susan Hegeman focuses on the term's history in the United States in the first half of the twentieth century. She shows how, during this period, the term \"culture\" changed from being a technical term associated primarily with anthropology into a term of popular usage. She shows the connections between this movement of \"culture\" into the mainstream and the emergence of a distinctive \"American culture,\" with its own patterns, values, and beliefs. Hegeman points to the significant similarities between the conceptions of culture produced by anthropologists Franz Boas, Edward Sapir, Ruth Benedict, and Margaret Mead, and a diversity of other intellectuals, including Randolph Bourne, Van Wyck Brooks, Waldo Frank, and Dwight Macdonald. Hegeman reveals how relativist anthropological ideas of human culture--which stressed the distance between modern centers and \"primitive\" peripheries--came into alliance with the evaluating judgments of artists and critics. This anthropological conception provided a spatial awareness that helped develop the notion of a specifically American \"culture.\" She also shows the connections between this new view of \"culture\" and the artistic work of the period by, among others, Sherwood Anderson, Jean Toomer, Thomas Hart Benton, Nathanael West, and James Agee and depicts in a new way the richness and complexity of the modernist milieu in the United States.",
"imageLinks": {
"smallThumbnail": "http://bks3.books.google.de/books/content?id=OwYWU2H3me4C&printsec=frontcover&img=1&zoom=5&edge=curl&source=gbs_api",
"thumbnail": "http://bks3.books.google.de/books/content?id=OwYWU2H3me4C&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api"
},
"createdAt": "2015-06-05T14:56:12.714Z",
"updatedAt": "2015-06-05T14:56:12.724Z",
"id": "5571b88c51861950360fac1c"
},
"rating": 4
},
{
"source": {
"_bsontype": "ObjectID",
"id": "Uq¸Q\u0019P6\u000f¬\u001c"
},
"rating": 12
}
]
As you can see rather than replacing the source id with the full source properties, it added the source as an object in the returned array, and then added another object with a new source id reference, and the summed rating amount. Strangely, it also attached just one of the rating values to the source object it appended to the results.
Is this what should be happening. I can't follow the logic and it feels a bit buggy. In any case, what I would like is to have the source within each returned row, alongside the summed total. Can anyone explain what's going on here, and if I made an error perhaps?

How to get audience_size in Interest plus Country query

Hi i'm still new in Facebook-ads-api I know this is a noob question,
I want to get the audience_size for the Interest in a specific country.
on the API sample it can only generate the whole world audience_size of an Interest
use FacebookAds\Object\TargetingSearch;
use FacebookAds\Object\Search\TargetingSearchTypes;
$results = TargetingSearch::search(
TargetingSearchTypes::INTEREST,
null,
'soccer'
);
// Sample Response
{
"data":[
{
"name":"Association football (Soccer)",
"id":6003107902433,
"audience_size":593326800,
"path":[
"Sports and outdoors",
"Sports",
"Association football (Soccer)"
],
"description":null
},
...other results...
]
}
In order to get the estimated audience, you can use the Reach Estimate.
You can see the documentation here: https://developers.facebook.com/docs/marketing-api/reference/ad-account/reachestimate/
Just pass the targeting object (which include the interest and the country) and get the result.

Returning objects with multiple types in a RESTful way

I'm currently designing an API to handle requests from mobile clients. To achieve some degree of decoupling between backend and client I would like to define the webservices in a RESTful way. The challenge that I am facing is returning multiple objects with different types for a single call.
Lets say we have the following Model:
Harbour ... Top level entry
Boat shed ... Assigned to a specific harbour (0..n)
Boat ... Assigned to a specific boat shed (0..n), or directly to a harbour (0..n)
As far as i understand REST, if I now want to display all the boats and sheds in the harbour I would send two requests:
/harbours/{harbour_id}/boats Returning a list of all boats. Boats in a shed would contain an id linking to the shed they are in
/harbours/{harbour_id}/sheds Returning a list of all sheds
As I want to use the web service in a mobile scenario, it would be ideal to combine these two calls into one. This could then either return the list of boats with the shed object nested within, or both object types side by side:
/harbours/22/boats
[
{
"id":1,
"boatName":"Mary",
"boatShed":{
"id":1,
"shedName":"Dock 1",
"capacity":55
}
},
{
"id":2,
"boatName":"Jane",
"boatShed":{
"id":1,
"shedName":"Dock 1",
"capacity":55
}
}
]
or
/harbours/22/boats
{
"boats":[
{
"id":1,
"boatName":"Mary",
"boatShedId":1
},
{
"id":2,
"boatName":"Jane",
"boatShedId":1
}
],
"sheds":[
{
"id":1,
"shedName":"Dock 1",
"capacity":55
}
]
}
My question now is, which of these ways is closer to the idea behind REST, or is it not RESTful at all?
As #Tarken mentioned /boats request should not return sheds in the top level (since the url assumes you're asking for collection of resource Boat)
If you have relations defined as follows
Harbour:
boats: Boat[]
sheds: Shed[]
Shed:
boats: Boat[]
Boat:
harbour: Harbour
shed: Shed
/harbours/ID then returns a Harbour representation with boats and sheds relation set.
{
boats:
[
{ Boat },
{ Boat },
..
],
sheds:
[
{ Shed },
{ Shed },
..
],
...
}
Nothing is against restful principles here - the url uniquely identifies a resource and resource representation can be anything, with links to other resources as well.
Create a Harbour model which contains both Boat Shed and Boat information. If i am implementing the service in Java, then i would have done something like this :
class Boat{
...
}
class BoatShed{
...
}
class Harbour{
List<Boat> boats;
List<BoatShed> boatSheds;
...
}
You can create an API like /api/harbours/{harbourId}.
As per your question you want to display all the boats and sheds in the harbour, say id=1234, you can make a request like this :
GET /api/harbours/1234
This will return list of Boats and list of Boat Sheds like this:
{
"boats":[
{
"id":1,
"boatName":"Mary",
"boatShedId":1
},
{
"id":2,
"boatName":"Mary2",
"boatShedId":2
}
],
"sheds":[
{
"id":1,
"shedName":"Dock 1",
"capacity":55
},
{
"id":2,
"shedName":"Dock 2",
"capacity":50
}
]
}
EDIT
As you want to get boats and Sheds side by side by sending one request, the api/hourbours/{id} looks good according to REST API design principles.
Getting all sheds while requesting for boats is not in accordance with ideal REST API design, but if you want to achieve the same you can d the following.
If you want that way, then first one /api//harbours/{id}/boats looks good to me.