I have searched the forums and stack overflow for it and still can't understand how to do this. I don't know how to parse the results for a specific album in the results. I want to get the photos for the profile pictures album. So far I got:
func retrieveFBProfileAlbum(){
print("RetrievingFBProfileAlbum")
FBSDKGraphRequest(graphPath: "me/albums/", parameters: ["fields": "name, photos"]).startWithCompletionHandler({ (connection, result, error) -> Void in
if (error == nil){
// let results = result as! NSDictionary
// print(result)
if let array: AnyObject = result["data"] {
for resultDict in array as! [AnyObject] {
if let resultDict = resultDict as? [String : AnyObject] {
for (name, value) in resultDict{
print("NAME A: \(name), VALUE A \(value)")
}
}
}
}
}else{
print(error.localizedDescription)
}
})
}
I got the results as id, name, photos, id, name, photos. Not sure what to do with this :( I can print only the names of the albums but I don't know how to get the pics of Profile Pictures album:/
Please help as Ive spent many hours on this and still can't get it.
Here's the console output for print(Name:
RetrievingFBProfileAlbum
NAME A: id, VALUE A 357463944266729
NAME A: photos, VALUE A {
data = (
{
"created_time" = "2016-05-04T11:04:02+0000";
id = 1192004844145964;
name = "Yess!!:) Our New Baby!:)100% Electric !";
},
{
"created_time" = "2016-04-29T12:58:29+0000";
id = 1189130857766696;
name = "Coming on Wed!!:)";
},
{
"created_time" = "2016-04-09T16:55:35+0000";
id = 1176951032318012;
name = "Celebrating the good times!:)\nSwietujemy dobre czasy!:)";
},
{
"created_time" = "2016-02-27T10:11:35+0000";
id = 1144990872180695;
name = "The card on the tv said: 'TV in working order. Help yourself' lol Found close to Canonbury station on the Pavement lol\nKartka na telewizorze mowi: 'Dzialajacy Telewizor Wez sobie' Znalezione niedaleko Canonbury Station w Londynie lol!";
},
{
"created_time" = "2016-02-20T21:44:56+0000";
id = 1141193462560436;
name = "Amazing gig in this place:)\nWspanialy koncert w tym miejscu:)";
},
{
"created_time" = "2016-02-20T15:00:47+0000";
id = 1141030565910059;
name = "Pretty rainy in Oxford today;)";
},
{
"created_time" = "2016-02-04T12:26:26+0000";
id = 1132017403478042;
},
{
"created_time" = "2016-02-04T12:15:08+0000";
id = 1132014160145033;
},
{
"created_time" = "2015-12-18T21:22:28+0000";
id = 1105697299443386;
},
{
"created_time" = "2015-12-18T21:13:21+0000";
id = 1105694492777000;
},
{
"created_time" = "2015-12-17T16:07:03+0000";
id = 1105120696167713;
name = "Oxford Circus! Lol!";
},
{
"created_time" = "2015-12-14T10:39:47+0000";
id = 1103646716315111;
name = "On the way to see our new house:)\nW drodze do naszego nowego domku:)";
},
{
"created_time" = "2015-12-12T16:08:24+0000";
id = 1102853349727781;
name = "I wonder what are they queuing for lol";
},
{
"created_time" = "2015-12-12T16:08:24+0000";
id = 1102853346394448;
name = "I wonder what are they queuing for lol";
},
{
"created_time" = "2015-12-05T13:38:44+0000";
id = 1099659323380517;
name = "Had a nice recording session today";
},
{
"created_time" = "2015-11-25T08:36:30+0000";
id = 1095105427169240;
name = "Morning Charm of London;)";
},
{
"created_time" = "2015-11-24T10:55:52+0000";
id = 1094653970547719;
name = "Working on a bigger app project for a client!:)";
},
{
"created_time" = "2015-11-21T19:03:42+0000";
id = 1093483963998053;
name = "Marta's Birthday Party!";
},
{
"created_time" = "2015-11-19T12:34:39+0000";
id = 1092463290766787;
},
{
"created_time" = "2015-11-19T12:07:40+0000";
id = 1092455410767575;
},
{
"created_time" = "2015-11-13T10:20:02+0000";
id = 1089819014364548;
name = "This picture was made by Jeremy Pollard";
},
{
"created_time" = "2015-11-12T22:59:17+0000";
id = 1089636391049477;
},
{
"created_time" = "2015-11-12T22:59:17+0000";
id = 1089636377716145;
},
{
"created_time" = "2015-11-12T22:59:17+0000";
id = 1089636341049482;
},
{
"created_time" = "2015-11-12T22:59:17+0000";
id = 1089636331049483;
}
);
paging = {
cursors = {
after = MTA4OTYzNjMzMTA0OTQ4MwZDZD;
before = MTE5MjAwNDg0NDE0NTk2NAZDZD;
};
next = "https://graph.facebook.com/v2.5/357463944266729/photos?access_token=EAARr4VZBUZB1sBAGkjT94xtdTntZBMlYfSGyeGdX7AV8UiejafZB3j3BUtcizUci4H7exNYhK8knZATvJlGqEK8ItBt7nA6avvNQmLp3FdLcxwK5as9kHvy10mmBDdP1m74LbLq07PfZBdZB7ZBYskogHthmjFSMlJ2XjAcWyGKh2fAQ2wgwmKVj59NlxjJMJmLLjFv6PPshfQZDZD&limit=25&after=MTA4OTYzNjMzMTA0OTQ4MwZDZD";
};
}
NAME A: name, VALUE A Mobile Uploads
NAME A: id, VALUE A 105303352816124
NAME A: photos, VALUE A {
data = (
{
"created_time" = "2016-03-17T13:03:22+0000";
id = 1157099090969873;
},
{
"created_time" = "2015-11-18T15:00:58+0000";
id = 1092093134137136;
},
{
"created_time" = "2015-11-17T16:03:07+0000";
id = 1091665917513191;
name = "Working on the app design for our newest productivity app! #productivity #wellbeing #mindfulness #ios #apps";
},
{
"created_time" = "2015-11-17T08:19:03+0000";
id = 1091515567528226;
name = "Morning Pages app coming soon!!";
},
{
"created_time" = "2015-11-10T21:23:09+0000";
id = 1088809341132182;
name = "Morning Pages app coming soon!!";
},
{
"created_time" = "2015-11-10T15:23:04+0000";
id = 1088690757810707;
name = "Working on the app design for our newest productivity app! #productivity #wellbeing #mindfulness #ios #apps";
},
{
"created_time" = "2015-11-09T15:22:10+0000";
id = 1088254854520964;
},
{
"created_time" = "2015-11-09T09:00:22+0000";
id = 1088140484532401;
name = "Code Imagination is working on a new app! #ios #morningpages #appdevelopment #appdesign";
},
{
"created_time" = "2015-11-08T19:20:02+0000";
id = 1087913804555069;
name = "Morning Ritual will clear your mind. Simple and already forgotten technique of well-being.";
},
{
"created_time" = "2015-11-07T16:03:03+0000";
id = 1087375167942266;
name = "My iPhone app is coming soon out! :)";
},
{
"created_time" = "2015-11-06T17:15:14+0000";
id = 1086951271317989;
},
{
"created_time" = "2015-11-05T18:01:33+0000";
id = 1086518038027979;
name = "Morning Ritual will clear your mind. Simple and already forgotten technique of well-being.";
},
{
"created_time" = "2015-11-05T17:15:12+0000";
id = 1086503548029428;
},
{
"created_time" = "2015-11-04T10:00:43+0000";
id = 1085954754750974;
},
{
"created_time" = "2015-11-03T18:00:11+0000";
id = 1085715074774942;
name = "Code Imagination is working on a therapeutic app! Coming Soon!";
},
{
"created_time" = "2015-11-03T13:10:04+0000";
id = 1085617851451331;
name = "Code Imagination is working on a new app! #ios #morningpages #appdevelopment #appdesign";
},
{
"created_time" = "2015-11-02T16:03:12+0000";
id = 1085240851489031;
name = ":)";
},
{
"created_time" = "2015-10-31T13:06:03+0000";
id = 1084283338251449;
name = "Morning Pages app coming soon!!";
},
{
"created_time" = "2015-10-31T08:19:08+0000";
id = 1084204508259332;
name = "Working on the app design for our newest productivity app! #productivity #wellbeing #mindfulness #ios #apps";
},
{
"created_time" = "2015-10-30T09:52:10+0000";
id = 1083819734964476;
name = "Working on a new app project!! :)";
},
{
"created_time" = "2015-10-22T16:43:44+0000";
id = 1080595525286897;
},
{
"created_time" = "2015-10-22T16:43:44+0000";
id = 1080595035286946;
},
{
"created_time" = "2015-08-22T05:57:16+0000";
id = 1050046911675092;
name = "Dziekuje wszystkim za zyczenia; )\nThx All for the Birthday Wishes :)";
},
{
"created_time" = "2015-05-20T10:12:04+0000";
id = 999296236750160;
name = "Little Bell in Japanese. Available soon! Meanwhile check the english version here: http://buff.ly/1GoTGIH";
},
{
"created_time" = "2015-05-19T14:18:40+0000";
id = 999010216778762;
name = "Little bell the Japanese Version available soon;))\nLittle Bell wersja Japonska dostepna wkrotce;)";
}
);
paging = {
cursors = {
after = OTk5MDEwMjE2Nzc4NzYy;
before = MTE1NzA5OTA5MDk2OTg3MwZDZD;
};
next = "https://graph.facebook.com/v2.5/105303352816124/photos?access_token=EAARr4VZBUZB1sBAGkjT94xtdTntZBMlYfSGyeGdX7AV8UiejafZB3j3BUtcizUci4H7exNYhK8knZATvJlGqEK8ItBt7nA6avvNQmLp3FdLcxwK5as9kHvy10mmBDdP1m74LbLq07PfZBdZB7ZBYskogHthmjFSMlJ2XjAcWyGKh2fAQ2wgwmKVj59NlxjJMJmLLjFv6PPshfQZDZD&limit=25&after=OTk5MDEwMjE2Nzc4NzYy";
};
}
I have pasted just the begining of the results as its quite long. I appreciate any help.
Related
I need to do web scraping for a website which has allowed robot access. Below is the robot.txt file's content.
User-agent: *
Disallow:
Sitemap:https://www.sample.com/sitemap-index.xml
But when I try to fetch the website's content using nokogiri, it's being detected.
Nokogiri::HTML(open('https://www.sample.com/search?q=test', :ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE))
Here the output:
> (Document:0x3fda40e7cf70 {
name = "document",
children = [
#(DTD:0x3fda40e9591c { name = "html" }),
#(Element:0x3fda40e8c95c {
name = "html",
attributes = [ #(Attr:0x3fda4071a598 { name = "style", value = "height:100%" })],
children = [
#(Element:0x3fda3fefa28c {
name = "head",
children = [
#(Element:0x3fda401a3088 {
name = "meta",
attributes = [ #(Attr:0x3fda40ebd7a0 { name = "name", value = "ROBOTS" }), #(Attr:0x3fda40ebd778 { name = "content", value = "NOINDEX, NOFOLLOW" })]
}),
#(Element:0x3fda4074faf4 {
name = "meta",
attributes = [ #(Attr:0x3fda3ff0beec { name = "name", value = "format-detection" }), #(Attr:0x3fda3ff0bed8 { name = "content", value = "telephone=no" })]
}),
#(Element:0x3fda401ca700 {
name = "meta",
attributes = [ #(Attr:0x3fda401c2050 { name = "name", value = "viewport" }), #(Attr:0x3fda401c217c { name = "content", value = "initial-scale=1.0" })]
}),
#(Element:0x3fda4079a284 {
name = "meta",
attributes = [ #(Attr:0x3fda4078bfb8 { name = "http-equiv", value = "X-UA-Compatible" }), #(Attr:0x3fda4078bf04 { name = "content", value = "IE=edge,chrome=1" })]
})]
}),
#(Element:0x3fda407e2e6c {
name = "body",
attributes = [ #(Attr:0x3fda430205f0 { name = "style", value = "margin:0px;height:100%" })],
children = [
#(Element:0x3fda4072e2a0 {
name = "iframe",
attributes = [
#(Attr:0x3fda3ff45214 {
name = "src",
value = "/_Incapsula_Resource?SWUDNSAI=28&xinfo=5-66719320-0%200NNN%20RT%281543054979096%20247%29%20q%280%20-1%20-1%20-1%29%20r%280%20-1%29%20B12%284%2c315%2c0%29%20U2&incident_id=245000650118470008-256430953704260629&edet=12&cinfo=04000000"
}),
#(Attr:0x3fda3ff451d8 { name = "frameborder", value = "0" }),
#(Attr:0x3fda3ff451b0 { name = "width", value = "100%" }),
#(Attr:0x3fda3ff45188 { name = "height", value = "100%" }),
#(Attr:0x3fda3ff45174 { name = "marginheight", value = "0px" }),
#(Attr:0x3fda3ff4514c { name = "marginwidth", value = "0px" })],
children = [ #(Text "Request unsuccessful. Incapsula incident ID: 245000650118470008-256430953704260629")]
})]
})]
})]
})
How can I achieve this web scraping?
I want to add table 'mm' to table 'fmenu.pages' but it doesnt work at all. Error: attempt to index a nil value (field 'main2'). Its about last line. Code:
local fmenu = {
selected_button = 0,
menu = {
font = 1,
},
pages = {
["main"] = {
name = "name",
id = 1,
btns = {
{name = "name I", id = 1}
}
}
}
}
local mm = {
["main2"] = {
name = "name2",
id = 2,
btns = {
{name = "name I", id = 1},
{name = "name II", id = 2}
}
}
}
table.insert(fmenu.pages, mm)
print(fmenu.pages["main2"].name)
How about using table.merge from lua-stdlib?
local table = require"std.table"
local fmenu = {
selected_button = 0,
menu = {
font = 1,
},
pages = {
["main"] = {
name = "name",
id = 1,
btns = {
{name = "name I", id = 1}
}
}
}
}
local mm = {
["main2"] = {
name = "name2",
id = 2,
btns = {
{name = "name I", id = 1},
{name = "name II", id = 2}
}
}
}
table.merge(fmenu.pages, mm)
print(fmenu.pages["main2"].name)
I need to filter this NSMutableDictionary on key value based where item_type= bad
i tried but not working
NSPredicate *pred=[NSPredicate predicateWithFormat:#"(item_type == %#)", #"Good"];
NSArray *resultArray = [[dummyDictionary allValues] filteredArrayUsingPredicate:pred];
NSLog(#"resultArray:%#",resultArray);
{
“Cat1” = (
{
"image_item" = “a”;
"item_type" = “Good”;
}
);
Cat2 = (
{
"image_item" = “b”;
"item_type" = Good;
},
{
"image_item" = “c”;
"item_type" = Bad;
},
);
Cat3 = (
{
"image_item" = “d”;
"item_type" = Good;
},
{
"image_item" = “e”;
"item_type" = Bad;
},
);
}
And need such output NSMutableDictionary
{
“Cat1” = (
);
Cat2 = (
{
"image_item" = “c”;
"item_type" = Bad;
},
);
Cat3 = (
{
"image_item" = “e”;
"item_type" = Bad;
},
);
}
NOTE: dummyDictionary is value i get from .plist
I have an array of objects that I parse from a JSON. My JSON looks like this;
- message: [
-{
movie_id: 30,
movie_name: "Scream",
category_name: "Horror"
},
-{
movie_id: 31,
movie_name: "Avengers",
category_name: "Action"
},
-{
movie_id: 32,
movie_name: "Friday the 13th",
category_name: "Horror"
},
-{
movie_id: 33,
movie_name: "The ring",
category_name: "Horror"
},
-{
movie_id: 34,
movie_name: "Die Hard",
category_name: "Action"
},
-{
movie_id: 35,
movie_name: "The ring 2",
category_name: "Horror"
},
....
Its a JSON array of movies that contains many movies. What I am unable to do is parse each object and arrange them by category_name in an array, so all the "horror" will be grouped together, all the action, and all the romance etc etc. However...I need to be able to place a String value at the start of each category. So the array might look like this:
Index
0 "Horror"
1 Movie Object
2 Movie Object
3 Movie Object
4 "Romance"
5 Movie Object
6 Movie Object
7 "Action"
8 Movie Object
9 Movie Object
10 Movie Object
I have movie object with the following paramters;
NSString *movie_id
NSString * movie_name
NSString *category_name
Any help is greatly appreciated.
I would suggest a slightly different structure for the parsed data.
Rather than an array of mixed strings and objects, why not create a dictionary (using the category names as keys) of arrays? Just iterate through your original JSON. For each movie object, check to see if the key exists for that category name. If it does not, add a new array as the value for that category name. Then add the movie object to the array.
Your final dictionary would be something like this:
#{ #"Horror" : #[obj1, obj2, obj 3],
#"Romance" : #[obj4, obj5, obj 6],
#"Action" : #[obj7, obj8, obj 9] }
That way you can iterate through each category, and also iterate through the movies is each category
Suppose You have your array message then you can arrange them as
NSArray *categories = [message valueForKeyPath:#"#distinctUnionOfObjects.category_name"];
NSMutableArray *results = [NSMutableArray new];
for (NSString *categoryName in categories)
{
NSArray *groupArray = [message filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:#"category_name = %#", categoryName]];
[results addObject:categoryName];
[results addObjectsFromArray:groupArray];
}
and your final array I mean results will be
(
Horror,
{
"category_name" = Horror;
"movie_id" = 30;
"movie_name" = Scream;
},
{
" movie_name" = "Friday the 13th";
"category_name" = Horror;
"movie_id" = 32;
},
{
"category_name" = Horror;
"movie_id" = 33;
"movie_name" = "The ring";
},
{
"category_name" = Horror;
"movie_id" = 35;
"movie_name" = "The ring 2";
},
Action,
{
"category_name" = Action;
"movie_id" = 31;
"movie_name" = Avengers;
},
{
"category_name" = Action;
"movie_id" = 34;
"movie_name" = "Die Hard";
}
)
Hope this is what you want.
But this not a good coding practice, to have different data types(string and dictionary) in same array. so you should parse them like this
NSArray *categories = [message valueForKeyPath:#"#distinctUnionOfObjects.category_name"];
NSMutableDictionary *results = [NSMutableDictionary new];
for (NSString *categoryName in categories)
{
NSArray *groupArray = [message filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:#"category_name = %#", categoryName]];
[results setObject:groupArray forKey:categoryName];
}
and your result will be.
{
Action = (
{
"category_name" = Action;
"movie_id" = 31;
"movie_name" = Avengers;
},
{
"category_name" = Action;
"movie_id" = 34;
"movie_name" = "Die Hard";
}
);
Horror = (
{
"category_name" = Horror;
"movie_id" = 30;
"movie_name" = Scream;
},
{
" movie_name" = "Friday the 13th";
"category_name" = Horror;
"movie_id" = 32;
},
{
"category_name" = Horror;
"movie_id" = 33;
"movie_name" = "The ring";
},
{
"category_name" = Horror;
"movie_id" = 35;
"movie_name" = "The ring 2";
}
);
}
Now choose whatever you want.
How do I extract each address from the NSDictionary I instantiated (below), so I can assign to various NSString objects?
I have the following JSON:
{
"Address":[
{
"$":{
"ID":"0"
},
"Address2":[
"10 Smith RD"
],
"City":[
"Mapleville"
],
"State":[
"NJ"
],
"Zip5":[
"90210"
],
"Zip4":[
"764"
]
},
{
"$":{
"ID":"1"
},
"Address2":[
"32 Hog CT"
],
"City":[
"New York City"
],
"State":[
"NY"
],
"Zip5":[
"90210"
],
"Zip4":[
"1390"
]
}
]
}
cData (below) came from the JSON above.
I did the following to convert to a NSDictionary:
NSDictionary* dictionary2 = [NSJSONSerialization JSONObjectWithData:cData options:NSJSONReadingAllowFragments error:nil];
once I did a:
NSLog(#"%#", dictionary2);
output from NSLog:
{
Address = (
{
"$" = {
ID = 0;
};
Address2 = (
"10 Smith RD"
);
City = (
"Mapleville"
);
State = (
NJ
);
Zip4 = (
7642
);
Zip5 = (
90210
);
},
{
"$" = {
ID = 1;
};
Address2 = (
"32 Hog CT"
);
City = (
"New York City"
);
State = (
NY
);
Zip4 = (
1390
);
Zip5 = (
90210
);
}
);
}
Just follow the structure.
NSDictionary* dictionary2 = [NSJSONSerialization ...
NSArray *addresses = dictionary2[#"Address"];
for (NSDictionary *addressData in addresses) {
NSString *address2 = addressData[#"Address2"];
NSString *city = addressData[#"City"];
// and the rest as needed
}