I'm trying to get the link to a Facebook Page's Post. However, links only show up under the actions field, and for every like, comment, or share, it lists the link again. I use:
[[[FBSDKGraphRequest alloc] initWithGraphPath:#"/v2.3/116178611870507/feed?limit=20" parameters:[NSMutableDictionary dictionaryWithObject:#"id, actions, message, full_picture" forKey:#"fields"]]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error)
The result shows up in console as
{
data = (
{
actions = (
{
link = "https://www.facebook.com/116178611870507/posts/534581860030178";
name = Comment;
},
{
link = "https://www.facebook.com/116178611870507/posts/534581860030178";
name = Like;
},
{
link = "https://www.facebook.com/116178611870507/posts/534581860030178";
name = Share;
}
);
I guess my question would be, how can I access the link in there, but limit to only pulling it one time instead of for every like share or comment?
Try this code :
NSMutableArray *link = [[NSMutableArray alloc]init];
NSMutableArray *dataArr = [[NSMutableArray alloc] initWithArray:[yourFacebookResult objectForKey:#"data"]];
for (int i=0; i < dataArr.count; i++) {
for (int j=0; j < [[[dataArr objectAtIndex:i] objectForKey:#"actions"] count]; j++) {
[link addObject:[[[[dataArr objectAtIndex:i] objectForKey:#"actions"] objectAtIndex:j] objectForKey:#"link"]];
}
}
NSLog(#"Your all link -> %#",link);
Related
I am calling the graph api to retrieve my user's events.And I get back an NSDictionary response. My problem is that I'm trying to access the names of the events but can't figure out the correct way of doing it. Can you please help me with this?
My response :
events = {
data = (
{
id = 16245704637388667;
name = "My event name";
place = {
id = 278379712223737;
location = {
city = Beijing;
country = China;
latitude = "53.598408783333";
....
Mycode to retrieve the vent name:
if ([result objectForKey:#"data"]){
NSArray *events = [result objectForKey:#"data"];
NSString *text=#"You don't have events!";
for (NSDictionary* myevent in events) {
NSString *myeventName = [myevent objectForKey:#"name"];
NSLog(#"%#",myeventName);
}
}
Found a solution:
[[[FBSDKGraphRequest alloc] initWithGraphPath:#"me/events" parameters: #{#"fields": #"name"}]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSMutableArray* events = [result objectForKey:#"data"];
events names = [events valueForKey:#"name"];
}
}];`
I am trying to download google calendar data.
I am following a tutorial this link according to which implementing some of the GoogleOAuth delegate methods will let me get my desired data.
First I converted the response JSON data into an NSDictionary object and after that, I, NSLog this dictionary, to see the way the returned data is formed which is as shown below.
calendarInfoDict is {
etag = "\"1436255371893000\"";
items = (
{
accessRole = owner;
backgroundColor = "#9a9cff";
colorId = 17;
defaultReminders = (
{
method = popup;
minutes = 30;
}
);
etag = "\"1436255371893000\"";
foregroundColor = "#000000";
id = "sabiranthapa#gmail.com";
kind = "calendar#calendarListEntry";
notificationSettings = {
notifications = (
{
method = email;
type = eventCreation;
},
{
method = email;
type = eventChange;
},
{
method = email;
type = eventCancellation;
},
{
method = email;
type = eventResponse;
}
);
};
primary = 1;
selected = 1;
summary = "sabiranthapa#gmail.com";
timeZone = "Asia/Calcutta";
},
{
accessRole = reader;
backgroundColor = "#92e1c0";
colorId = 13;
defaultReminders = (
);
description = "Displays birthdays of people in Google Contacts and optionally \"Your Circles\" from Google+. Also displays anniversary and other event dates from Google Contacts, if applicable.";
etag = "\"1436255358367000\"";
foregroundColor = "#000000";
id = "#contacts#group.v.calendar.google.com";
kind = "calendar#calendarListEntry";
summary = Birthdays;
timeZone = "Asia/Calcutta";
}
);
kind = "calendar#calendarList";
nextSyncToken = 00001436255371893000;
}
According to tutorial there is a block containing a bunch of information regarding every calendar I have created in Google Calendars inside curly bracket. But I am not getting any events that I have saved which can be seen in Google Calendar after signing in gmail but not in my apps where I need to work with it.
My code is
-(void)responseFromServiceWasReceived:(NSString *)responseJSONAsString andResponseJSONAsData:(NSData *)responseJSONAsData{
NSError *error;
if ([responseJSONAsString rangeOfString:#"calendarList"].location != NSNotFound) {
NSDictionary *calendarInfoDict = [NSJSONSerialization JSONObjectWithData:responseJSONAsData options:NSJSONReadingMutableContainers error:&error];
NSLog(#"calendarInfoDict is %#", calendarInfoDict);
if (error) {
NSLog(#"%#", [error localizedDescription]);
}
else{
NSArray *calendarsInfo = [calendarInfoDict objectForKey:#"items"];
if (_arrGoogleCalendars == nil) {
_arrGoogleCalendars = [[NSMutableArray alloc] init];
}
for (int i=0; i<[calendarsInfo count]; i++) {
NSDictionary *currentCalDict = [calendarsInfo objectAtIndex:i];
NSArray *values = [NSArray arrayWithObjects:[currentCalDict objectForKey:#"id"],
[currentCalDict objectForKey:#"summary"],
nil]; NSArray *keys = [NSArray arrayWithObjects:#"id", #"summary", nil];
[_arrGoogleCalendars addObject:
[[NSMutableDictionary alloc] initWithObjects:values forKeys:keys]];
}
_dictCurrentCalendar = [[NSDictionary alloc] initWithDictionary:[_arrGoogleCalendars objectAtIndex:0]];
[_barItemPost setEnabled:YES];
[_barItemRevokeAccess setEnabled:YES];
[self showOrHideActivityIndicatorView];
But I always end up with condition
if (_arrGoogleCalendars == nil) {
_arrGoogleCalendars = [[NSMutableArray alloc] init];
}
without able to access my events.
How can I download (or access) my Events from google calendar?
I have written an IOS App to retrieve data from the Facebook account from the user's phone. I can retrieve data like Name, Profilepicture, ... (after the user logged in with his Facebook account details).
I cannot retrieve the status of the user, more specifically the feelings (smilies) posted, like: "Feeling good", "Feeling proud", ...
I have tried the following code:
self.userprofilePicture.profileID = user.objectID; // works fine
self.userUsername.text = user.first_name; // works fine
self.userEmail.text = [user objectForKey:#"email”]; // works fine
self.userStatus.text = [result objectForKey:#"status"]; // no result
I have also tried the following:
if ([user objectForKey:#"status"]) {
NSArray *temp = [user objectForKey:#"status"];
for (int i = 0; i < [temp count]; i++) {
self.userStatus.text = [NSString stringWithFormat:#“User Status: %d, %#", i, self.temp];
}
}
Is it possible to retrieve the "feelings" information from Facebook?
I'm new to ios and its developing. i have clean code with set Correctly AFNetworking.My base URl's json Encording has got JSON objects and arrays as well as values . in my JSON out put i want to get values of "thumbnail" every time i do im getting Null .please help me to get "name ,thumbnail,id,images " of my json output. please find my NSDictionary type printed object's NSlog.
2014-07-20 09:08:33.110 WADTourisum[1157:60b] Reachability Flag Status: -R ------- networkStatusForFlags
2014-07-20 09:08:33.879 WADTourisum[1157:60b] JSON: {
Main = (
{
id = 1;
"image_bundle_id" = 1;
images = (
"http://wearedesigners.net/clients/clients12/tourism/images/guides/oceans/slide_images/1.jpg",
"http://wearedesigners.net/clients/clients12/tourism/images/guides/oceans/slide_images/2.jpg",
"http://wearedesigners.net/clients/clients12/tourism/images/guides/oceans/slide_images/3.jpg"
);
name = OCEAN;
thumbnail = "http://wearedesigners.net/clients/clients12/tourism/images/guides/thumbs/ocean.jpg";
},
{
id = 2;
"image_bundle_id" = 23;
images = (
"http://wearedesigners.net/clients/clients12/tourism/images/guides/heritages/slide_images/1.jpg",
"http://wearedesigners.net/clients/clients12/tourism/images/guides/heritages/slide_images/2.jpg",
"http://wearedesigners.net/clients/clients12/tourism/images/guides/heritages/slide_images/3.png"
);
name = Heritage;
thumbnail = "http://wearedesigners.net/clients/clients12/tourism/images/guides/thumbs/heritage.jpg";
},
{
id = 3;
"image_bundle_id" = 0;
images = (
);
name = "Tea Country";
thumbnail = "http://wearedesigners.net/clients/clients12/tourism/images/guides/thumbs/teaCountry.jpg";
},
{
id = 4;
"image_bundle_id" = 0;
images = (
);
name = "WILD LIFE";
thumbnail = "http://wearedesigners.net/clients/clients12/tourism/images/guides/thumbs/wildLife.jpg";
},
{
id = 5;
"image_bundle_id" = 0;
images = (
);
name = Culture;
thumbnail = "http://wearedesigners.net/clients/clients12/tourism/images/guides/thumbs/culture.jpg";
},
{
id = 6;
"image_bundle_id" = 0;
images = (
);
name = "NIGHT LIFE";
thumbnail = "http://wearedesigners.net/clients/clients12/tourism/images/guides/thumbs/nightLife.jpg";
}
);
}
my code snippit
-(void) retriveData
{
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:#"http://www.fr20.wearedesigners.net/WADMac/tourism/fetchGuideListAndroid.php"
parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
self.posts =(NSDictionary *)responseObject;
self.post =self.posts[#"thumbnail"];
NSLog(#"JSON: %#", self.post);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Please log into internetet"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alertView show];
}];
}
You are getting the response and the only problem i see is you are not able to retrieve values correctly.
While fetching data from JSON remember that in which format you are getting the data i.e. either you are getting arrays or dictionary.
Seeing your response you are getting Array which in itself contains dictionary.
use the below code to fetch the values
NSArray *array = [responseObject valueForKey:#"Main"];
for (NSDictionary *dict in array) {
NSInteger ids = [[dict valueForKey:#"id"] integerValue];
NSString *name = [dict valueForKey:#"name"];
NSString *thumbnail = [dict valueForKey:#"thumbnail"];
NSArray *arrImages = [dict valueForKey:#"images"];
//You can use them accordingly
}
Hope this helps you. Happy coding :)
Have you ever tried to get data fields from the address book and ran into the wonderful world of ABPerson reference only to find it reads like the blueprints to a space rocket?
I've gotten so far but I still need help getting just the Twitter username key & value:
//I tried this but I can't seem to get the if statement to work
ABMutableMultiValueRef socialMulti = ABRecordCopyValue(person, kABPersonSocialProfileProperty);
NSMutableDictionary *mySocialDict = [NSMutableDictionary dictionaryWithCapacity:ABMultiValueGetCount(socialMulti)];
NSLog(#"entering social dict of count %ld", ABMultiValueGetCount(socialMulti));
for (CFIndex i = 0; i < ABMultiValueGetCount(socialMulti); i++) {
CFStringRef socialLabel = ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(socialMulti, i));
CFStringRef social = ABMultiValueCopyValueAtIndex(socialMulti, i);
if ([(__bridge NSString*)socialLabel isEqualToString:#"twitter"]) {
NSLog(#"we got a twitter");
}
[mySocialDict setObject:(__bridge NSString*)social forKey:(__bridge NSString*)socialLabel];
NSLog(#"social is %#",social);
CFRelease(social);
CFRelease(socialLabel);
}
I'm actually just interested in the twitter username. I know I could get it from the dictionary I created but I want to get it directly. I plan to eliminate the NSDictionary step anyway.
Here's an excerpt from my code. Replace your var names as necessary.
ABMultiValueRef socialMulti = ABRecordCopyValue(recordRef, kABPersonSocialProfileProperty);
NSMutableArray* twitterHandlesArray = [[NSMutableArray alloc] initWithCapacity:ABMultiValueGetCount(socialMulti)];
for (CFIndex i = 0; i < ABMultiValueGetCount(socialMulti); i++) {
NSDictionary* social = (__bridge NSDictionary*)ABMultiValueCopyValueAtIndex(socialMulti, i);
if ([social[#"service"] isEqualToString:(__bridge NSString*)kABPersonSocialProfileServiceTwitter]) {
NSString* username = (NSString*)social[#"username"];
NSLog(#"we got a twitter. username is %#", username);
[twitterHandlesArray addObject:[[username conditionedAsTwitterHandle] SHA2Digest]];
}
}