Retrieve news feed using facebook API - api

Hi I have been looking for hours but cannot find the API call that retrieves a user's news feed (i.e the thing that you see at http://www.facebook.com/home.php). I think this should be something extremely easy. What did I miss?
I would prefer an answer with FQL, but other API methods will be just fine, as I think I can translate between them.

https://graph.facebook.com/me/home
Note: /me/home retrieves an outdated view of the News Feed. This is currently a known issue and we (Facebook) don't have any near term plans to bring them back up into parity.

I found it! The way is to look in the stream for post from users that are your friends. This is kind of annoying because it takes double the effort just to do some very basic task. In Objective-C using FBConnect the code look like this:
NSString *connections = [NSString stringWithFormat:#"select target_id from connection where source_id == %lld", _uid];
NSString *fql = [NSString stringWithFormat:#"select message from stream where source_id in (%#)", connections];
NSDictionary* params = [NSDictionary dictionaryWithObject:fql forKey:#"query"];
[[FBRequest requestWithDelegate:self] call:#"facebook.fql.query" params:params];

http://developers.facebook.com/docs/reference/fql/stream
the first example is how to properly get the news feed.

Related

KeychainWrapper Objective C Identifier and Key questions

I’m new to both in app purchases and using the keychain. I am using Objective C and KeychainItemWrapper.
For now I want to simply store a number in the keychain. I don’t want anyone outside the app to be able to change it, and while I don’t much care if anyone can see it, I would like to understand what’s encrypted and what’s not as I may want to store private data later.
I have successfully stored a number and retrieved, even after deleting and reinstalling the app, but I’m not at all sure I’m doing it right. How does one choose an identifier and which keys are appropriate?
As you’ll see, I’m pretty unclear on the concepts.
First question: What is the “identifier” and why can’t I use more than one?
Here’s the code:
#property (nonatomic, strong) KeychainItemWrapper *myChain;
. . .
if (myChain == nil)
{
// first question: what identifier should I use?
myChain = [[KeychainItemWrapper alloc] initWithIdentifier:#"test" accessGroup:nil];
}
So once I’ve used the identifier “test”, it appears that I’m stuck with it on this phone. If I use any other value then KeychainItemWrapper fails “unable to add item”. I don’t understand this at all. How do I create different identifiers? Do I want to or need to? What exactly is this identifying?
Moving on to storing. Per the code below, I can store a number, description and comment.
// storing:
// let’s start with the number 10
NSString *testNum = #"10";
NSString *testDescr = #"this is a line of text";
[myChain setObject:testDescr forKey:(__bridge id)(kSecAttrDescription)];
[myChain setObject:testNum forKey:(__bridge id)(kSecValueData)];
[myChain setObject:#"This is a comment" forKey:(__bridge id)(kSecAttrComment)];
// retrieving:
NSString *descOut = [myChain objectForKey: (__bridge id)kSecAttrDescription];
NSData *numberOut = [myChain objectForKey: (__bridge id)(kSecValueData)];
And this all works fine.
But what are the appropriate keys for this usage? I just picked a few at random for testing.
Thank you, I know I’m asking a lot, but I’ve been through the docs and stack overflow and various tutorials and I haven’t really got a good understanding of this.

How to use ios 6 challenge in game centre

Firstly,
I am fairly new to objective c / xcode dev so there is a good chance i am being a muppet. I have written a few simple apps to try things and my most recent one has been testing the gamecentre classes / functionality.
i have linked ok to leaderboards and achievements - but i can't get challenges working.
I have added the following code.... which is in my .m
GKLeaderboard *query = [[GKLeaderboard alloc] init];
query.category = LoadLeaderboard;
query.playerScope = GKLeaderboardPlayerScopeFriendsOnly;
query.range = NSMakeRange(1,100);
[query loadScoresWithCompletionHandler:^(NSArray *scores, NSError *error)
{NSPredicate *filter = [NSPredicate predicateWithFormat:#"value < %qi", scoreint];
NSArray *lesserScores = [scores filteredArrayUsingPredicate:filter];
[self presentChallengeWithPreselectedScores: lesserScores];
}
];
this code is basically taken from apple, just replacing the variable names....
this however gives an error on
[self presentChallengeWithPreselectedScores: lesserScores];
error Implicit conversion of an Objective-C pointer to 'int64_t *' (aka 'long long *') is disallowed with ARC
LoadLeaderboard is defined as a string
scoreint is defined as integer, thought this may be issue as not int64_t but that does not seem to make a difference.
I am sure for someone who has any kind of a clue this is a straightforward fix. But i am struggling at the moment. So if anyone can be kind and help a fool in need it would be most appreciated
Thanks,
Matt
welcome to Stack Overflow. I don't know your implementation of presentChallengeWithPreselectedScores method so I can't tell (although it looks like the method is taking a 64 bit integer and you're trying to feed it an array).
There are two ways to issue challenges:
1 - This is the easier way - if you've successfully implemented leader boards and score posting to game center, the challenges work out of the box in iOS6, the user can always view the leader board - select a submitted score (or a completed achievement) and select "Challenge Friend".
2 - The second way is to build a friend picker and let the user issue challenges within your game. But considering you're new to objective-c and game center, it's not so easy. But for your reference here is how you do it:
when you submit a GKScore object for the leaderboards - you can retain and use that GKScore object (call it myScoreObject) like this:
[myScoreObject issueChallengeToPlayers:selectedFriends message:yourMessage];
where selectedFriends is an NSArray (the friend picker should generate this) - the message is optional and can be used only if you want to send a message to challenged friends.

How do I programmatically find the user's logging directory?

Given an app called ExampleApp, I want to find "~/Library/Logs/ExampleApp" basically without using hard coded paths. There exists NSSearchPathForDirectoriesInDomains, which you can use to find things like "~/Library/Application Support/ExampleApp" using the NSApplicationSupportDirectory search term, but there doesn't seem to be a search term for logging.
I don't think ~/Library/Logs is non-standard, since CrashReporter puts its logs there.
Try this :
NSString* libraryPath = [NSHomeDirectory stringByAppendingPathComponent:#"Library/Logs"];
Update (~/Library/Logs/AppName) :
NSString* bundleName = [[[NSBundle mainBundle] infoDictionary] objectForKey:#"CFBundleName"];
NSString* logsPath = [NSString stringWithFormat:#"Library/Logs/%#",bundleName];
NSString* libraryPath = [NSHomeDirectory stringByAppendingPathComponent:logsPath];
Cocoa doesn't provide a means for finding all of the standard directories. The old FSFindFolder() function can provide many more, but does involve converting from an FSRef back to a path or URL. Apple discourages its use, but it's still the only way to get certain standard directories without hard-coding. That said, it won't ever incorporate your app name. You have to append that.
Edited to add: the link to the legacy docs.

passing JSON from ASIHTTPRequest to django

I've exhausted other threads, so I'm posting this question here. Please pardon any newbie mistakes I've made along the way. I've been reading a lot, and I think I'm getting confused.
The Goal:
I'm trying to pass data from a form in objective-c to my django web service. In an effort to assist with this, I've employed the ASIHTTPRequest class to facilitate information transfer. Once sent to the web service, I'd like to save that data to my sqlite3 database.
Procedure:
On the Objective-C side:
I've stored the inputted form data and their respective keys in an NSDictionary, like this:
NSDictionary *personInfo = [NSDictionary dictionaryWithObjectsAndKeys:firstName.text, #"fName", middleName.text, #"mName", lastName.text, #"lName", nil];
I've added it to my ASIHTTPRequest in a different class by using a delegate. I've made the NSDictionary the same as above in the code block below for simplicity, like so:
NSString *jsonPerson = [personInfo JSONRepresentation];
[request addRequestHeader: #"Content-Type" value:#"application/json; charset=utf-8"];
[request appendPostData:[jsonPerson dataUsingEncoding:NSUTF8StringEncoding]];
[request setRequestMethod:#"POST"];
[request startAsynchronous];
And a NSLog shows the string I'm passing to look like this, which validates at least in JSONLint
{"mName":"Arthur","lName":"Smith","fName":"Bob"}
Because I'm seeing what appears to be valid JSON coming from my ASIHTTPRequest, and actions are running from requestfinished: rather than requestfailed:, I'm making the assumption that the problem more than likely isn't on the Objective-C side, but rather on the django side.
Here's what I've tried so far:
json.loads(request.POST)
>>expected string or buffer
json.loads('request.POST')
>>no JSON object to decode
json.loads(request.raw_post_data)
>>mNamelNamefName
incoming = request.POST
>>{"mName":"Arthur","lName":"Smith","fName":"Bob"}
incoming = request.POST
onlyValues = incoming.iterlists()
>>(u'{"mName":"Arthur","lName":"Smith","fName":"Bob"}', [u''])
...and a smattering of other seemingly far-fetched variations. I've kept a log, and can elaborate. The only hope I've been able to find is in the last example; it looks like it's treating the entire string as the key, rather than breaking up each dict object and key as I would have expected.
I realize this is terribly elementary and I don't normally ask, but this problem has me particularly stumped. I do also remember reading somewhere that python won't recognize the double-quotes around each object and key, that to get it to something django likes, each should be surrounded by single-quotes. I just don't have any idea how to get them that way.
Thanks!
This might be a little cumbersome but you may try some simple regexp in objective c just to see if that is really the case
NSError *error = NULL;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:#"\"" options:NSRegularExpressionCaseInsensitive error:&error];
NSString *json = [regex stringByReplacingMatchesInString:jsonPerson options:0 range:NSMakeRange(0, [jsonPerson length]) withTemplate:#"'"];
There might be some errors because I didn't run the code.

Get text after certain point using NSString

I am getting a url of a file when a user opens one from an NSOpenPanel for example like so:
/Users/Name/Documents/MyFile.png
So I just want this bit:
MyFile.png
However the user could have a file name of any length so how can I say, only get the string after the last forward slash (/)? I just want to get the file name.
NSString *fileName = [someStringContainingAPath lastPathComponent];
More general advice: spend a little time reading through the reference pages for NSString and NSString(UIStringDrawing). There are a lot of useful methods in there that you might not otherwise know to look for. In addition to -lastPathComponent demonstrated above, there's -pathComponents, -componentsSeparatedByString:, and many other handy tools.