I am trying to make an iPhone application - it's a Facebook wall viewer. However, I can't get more then 25 posts.
I heard that this is the default. Can this value be changed?
Here's my code:
- (void) getWallList {
currentApiCall = GETWALLLIST;
AppDelegate *delegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
[[delegate facebook] requestWithGraphPath:#"/me/home" andDelegate:self];
}
Yes you can change that one by setting the limit parameter to your Facebook api.
You can set that by passing limit to the params dict.
Have a look at the Facebook api under the heading Paging, in which you can pass limit and until params
Take a look at the below sample for your reference.
params = [[NSMutableDictionary alloc] initWithObjectsAndKeys: [NSString stringWithFormat:#"%d", yourLimit,], #"limit", untilString, #"until", nil];
[[delegate facebook] requestWithGraphPath:#"me/home" andParams:params andDelegate:self];
where yourLimit is the limit variable and you can set the until's value from the api response with the key paging
Hope this helps you.
Related
I'm new to iOS development, I have successfully integrated facebook login and such... however my problem is with the Score api. i can read the score but i cant seem to post it, i have the publish_actions permission and also am getting back a valid access_token.Not sure what the problem it, here is my code -
NSString *accessTokenToUse = [NSString stringWithFormat:#"%#",[self.facebook accessToken] ];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
//#"233", #"score",
accessTokenToUse, #"access_token",
nil];
NSMutableDictionary *paramsB = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"233", #"score",
accessTokenToUse, #"access_token",
nil];
NSLog(#"APP ACCESS TOKEN: %#",accessTokenToUse);
[self.facebook requestWithGraphPath:#"me/scores" andParams:paramsB andHttpMethod:#"POST" andDelegate:self];
[self.facebook requestWithGraphPath:#"APP_ID/scores" andParams:params andHttpMethod:#"GET" andDelegate:self];
***EDIT - Still doesn't work
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"233", #"score",
#"[APP_ACCESS_TOKEN (omitted for stackoverflow)]", #"access_token", nil];
[self.facebook requestWithGraphPath:#"/[userID]/scores" andParams:params andHttpMethod:#"POST" andDelegate:self];
EDIT - SOLVED
So bascially i WAS passing in the correct token, however the facebook sdk was overwriting it in Facebook.m to the user's access token. So the fix was simple - whenever i need to pass in the App's token i just add an other parameter < key=#"useAppToken" Value=#"yes" > and in Facebook.m just add an if statement within isSessionValid -
- (FBRequest*)openUrl:(NSString *)url
params:(NSMutableDictionary *)params
httpMethod:(NSString *)httpMethod
delegate:(id<FBRequestDelegate>)delegate {
NSLog(#"PARAMS BFORE: %# ", params);
[params setValue:#"json" forKey:#"format"];
[params setValue:kSDK forKey:#"sdk"];
[params setValue:kSDKVersion forKey:#"sdk_version"];
if ([self isSessionValid]) {
if ([params objectForKey:#"useAppToken"] == nil || [params objectForKey:#"useAppToken"] == #"no") {
[params setValue:self.accessToken forKey:#"access_token"];
}
}
NSLog(#"PARAMS AFTER: %# ", params);
[self extendAccessTokenIfNeeded];
FBRequest* _request = [FBRequest getRequestWithParams:params
httpMethod:httpMethod
delegate:delegate
requestURL:url];
[_requests addObject:_request];
[_request addObserver:self forKeyPath:requestFinishedKeyPath options:0 context:finishedContext];
[_request connect];
return _request;
}
Be sure to comment out the NSLogs in this... :)
Scores can only be published using application access_token and not one for user (which you probably using, it's ok for reading the scores but don't allow you to publish 'em).
Citing the Scores documentaion:
Create or update a score for a user
You can post a score or a user by issuing an HTTP POST request to /USER_ID/scores with the app access_token as long as you have the publish_actions permission.
Looks like it's a bug:
http://developers.facebook.com/bugs/461900043821056
But if you change your app settings to web app instead of native it would work.
I'm trying to use the Facebook iOS "feed" dialog call to allow my app's user to share something on their Facebook wall. When the facebook app is not installed, it attempts to let them authenticate within the app (presumably using a web view). The issue is that this dialog just disappears once they authenticate. I was expecting the web view to return to the "feed" sharing view.
How do I detect that they authenticated so that I can re-open the feed dialog?
I've added fbDidLogin to my app delegate, but it's not being called. (I wasn't sure if this would normally be called or not, but I read several people recommending this.)
SBJSON *jsonWriter = [SBJSON new];
// The action links to be shown with the post in the feed
NSArray* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:
#"More Videos",#"name",#"http://www.example.com/",#"link", nil], nil];
NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Test Caption", #"caption",
#"Test Description", #"description",
#"https://s3.amazonaws.com/example/images/test.png",
#"source",
self.video.blogLink, #"link",
#"01234567890123", #"app_id",
actionLinksStr, #"actions",
nil];
[delegate facebook].sessionDelegate = delegate;
[[delegate facebook] dialog:#"feed" andParams:params andDelegate:self];
It turns out the issue is the same as those reporting that the dialog disappears immediately for them. There is a bug in the Facebook SDK in regards to handling error -999, with the solution described in this comment on SO.
I finally realized I was having the same issue (albeit manifesting slightly differently), when I started listening to the FBDialogDelegate's method:
- (void)dialog:(FBDialog*)dialog didFailWithError:(NSError *)error
The error description referenced the -999 error mentioned above, leading me to the answer. Luckily the code checked into github worked flawlessly. I just had to pull it into the SDK codebase and recompile the .a lib file, then include it into my project.
Did you implemented facebook protocol FBSession in your view controller ?
To detect that user is authenticated you have to call isSessionValid:
if (![[self.fbAppDelegate facebook] isSessionValid]) {
NSArray *permissions = [[NSArray alloc] initWithObjects:#"publish_stream",#"create_event",#"offline_access", nil];
[[self.fbAppDelegate facebook] authorize:permissions];
}
and authorize inApp:
[self authorizeWithFBAppAuth:NO safariAuth:NO];
I want to get profile image of facebook friends. I know I can do this in code by getting id of user and using this link: userID/picture">http://graph.facebook.com/userID/picture. Is there easier way to get profile image directly from facebook sdk?
The Facebook SDK uses the same user ID and path to its graph. So I think it is not easier. But the same.
what about getting the url of the profile picture? then use something like SDWebImage to display the image and cache it to device. or any open source library that can display and cache image just by passing the url to it?
then, get the userIDs of his friends. save them in NSArray. then create a fql.
-(void)getFriendsInfo:(NSArray*)userIDs
{
//prepare param
NSMutableString *paramStr = [[NSMutableString alloc]init];
for (int i = 0; i<[userIDs count]; i++) {
if ([[userIDs objectAtIndex:i] isKindOfClass:[NSDecimalNumber class]]) {
NSString *tempParam = [NSString stringWithString:[[userIDs objectAtIndex:i]stringValue]];
[paramStr appendFormat:#"'%#',", tempParam];
}
}
[paramStr appendFormat:#"%#",#"'9999999999999'"];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSString stringWithFormat:#"SELECT uid, name, pic FROM user WHERE uid IN (%#)", tempParam], #"query",
nil];
//in my case, I declared Facebook *facebook; in my app delegate using the latest fb sdk
MyAppDelegate *delegate = (MyAppDelegate *) [[UIApplication sharedApplication] delegate];
[[delegate facebook] requestWithMethodName:#"fql.query"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
}
handle the data in delegate method
- (void)request:(FBRequest *)request didLoad:(id)result
I have an iPhone/iPad app that does some basic photo editing and gives the user the option to upload the finished product to Facebook. The app has more than 100,000 users and the majority seem to have no problem uploading their photos to Facebook. However, there are a handful of users that cannot seem to get their photos to upload no matter what they try. I have worked with them to ensure it is not app permissions or Facebook settings blocking them and cannot find any problem there. So I'm wondering if I am doing something incorrectly with FBConnect that is causing the problem to crop up once in a while. Here is the code:
- (void)initFacebook {
if( self.facebook == nil ) {
Facebook *fb = [[Facebook alloc] init];
self.facebook = fb;
[fb release];
}
if( [self.facebook isSessionValid] ) {
[[NSNotificationCenter defaultCenter] postNotificationName:#"FacebookIsReady"
object:nil
userInfo:nil];
} else {
NSArray *perms = [NSArray arrayWithObjects:#"publish_stream", #"user_likes", nil];
[self.facebook authorize:MY_FB_APP_ID permissions:perms delegate:self];
}
}
-(void)fbDidLogin {
[[NSNotificationCenter defaultCenter] postNotificationName:#"FacebookIsReady"
object:nil
userInfo:nil];
}
// this is in a different class
- (void)facebookIsReady:(NSNotification *)notification {
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:self.theImage, #"source", nil];
[appDelegate.facebook requestWithGraphPath:#"/me/photos"
andParams:params
andHttpMethod:#"POST"
andDelegate:appDelegate];
}
In the FBRequestDelegate the didLoad is always called even when the photo fails to appear in the Facebook profile. So what I'm getting at is the code never seems to fail but the photo doesn't always appear on the Facebook profile.
Is it possible that the app is not able to create a new album on the users profile? I have seen others report this problem before on various groups but have never found an actual solution. Thanks.
You have to include user_photos in your permissions array like this:
NSArray *permissions = [[NSArray alloc] initWithObjects:
#"user_photos",
#"publish_stream",
#"user_likes",
nil];
Here is the list of all the permissions: https://developers.facebook.com/docs/reference/api/permissions/
Uploading Photo on Facebook vie Social Framework is much easier .
Pleae check the below link
Fabecook Sharing
I'd be grateful for any suggestions as to how to deal with a problem I'm having posting an image to Facebook.
The following code works just as I would expect:
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"http://myserver/img.png", #"picture",
#"My Testing", #"name",
#"Enter some text...", #"message",
nil];
[appDelegate.facebook dialog:#"feed" andParams:params andDelegate:self];
However, I really want to use an image that I capture from my camera. I've set up the code to do that earlier in my application and I've put the image on the screen. So, I tried to do this:
CGRect contextRect = CGRectMake(0, 0, 320, 436);
UIGraphicsBeginImageContextWithOptions(contextRect.size, YES, 1);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
I've tested this code and newImage is a valid UIImage that I can place and manipulate just as I'd expect. However, when I try to integrate it into the Facebook dialog as follows:
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
newImage, #"picture",
#"My Testing", #"name",
#"Enter some text...", #"message",
nil];
[appDelegate.facebook dialog:#"feed" andParams:params andDelegate:self];
I get these two ridiculous messages in the console:
-[UIImage length]: unrecognized selector sent to instance 0x1c9420
CoreAnimation: ignoring exception: -[UIImage length]: unrecognized selector sent to instance 0x1c9420
So, as a test, I thought I'd try importing an image into my project and accessing it directly. This is the exact image as I referenced online in the first example, so I know it should work. But even when I try this:
UIImage *newImage = [UIImage imageNamed:#"BaB.png"];
I get the same error messages as above.
I see in the Facebook documentation that the "picture" key is supposed to use the URL to an image. But I've seen some examples online that indicate that folks are using an UIImage instead of just an URL.
Clearly, I'm doing something wrong, but I have no idea what it might be.
I'd be very grateful for any pointers as to how to proceed.
A summarized answer that outlines the process...key point is to include the access_token in the graph calls since the facebook-ios-sdk doesn't do this automatically:
1)Update to the latest facebook-ios-sdk.
2)Instantiate with app id.
self.facebook = [[Facebook alloc] initWithAppId:kApplicationFBID];
3) Authorize the app including publish_stream
NSArray * neededPermissions = [[[NSArray alloc] initWithObjects:#"user_about_me", #"publish_stream", #"user_photos", nil] autorelease];
[facebook authorize:neededPermissions delegate:appDelegate];
4) Ensure app delegate fBDidLogin captures and stores the access token & expiration in user defaults (for later optimization of login process).
-(void)fbDidLogin {
DebugLog(#"New Access Token: %#", [facebook accessToken] );
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:#"FBAccessTokenKey"];
[defaults setObject:[facebook expirationDate] forKey:#"FBExpirationDateKey"];
[defaults synchronize];
}
5) Confirm valid access token (non nil and not expired)...otherwise re authorize app per above.
6) Capture image to UIImage & call this noting the critical addition of the access_token. This will auto create an album for your app and put the image there and post it on the wall per my testing.
-(void)postImageToAlbum:(UIImage *)image {
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
image, #"source",
#"caption desc", #"message",
nil];
[facebook requestWithGraphPath:[NSString stringWithFormat:#"/me/photos?access_token=%#", self.facebook.accessToken]
andParams:params andHttpMethod:#"POST" andDelegate:self];
}
7) Check for id result in FBRequestDelegate method
-(void)request:(FBRequest *)request didLoad:(id)result {
NSLog(#"Request didLoad: %# ", [request url ]);
if ([result isKindOfClass:[NSArray class]]) {
result = [result objectAtIndex:0];
}
if ([result isKindOfClass:[NSDictionary class]]){
}
if ([result isKindOfClass:[NSData class]]) {
}
NSLog(#"request returns %#",result);
}
8) DO NOT USE a test user account for testing...currently it will auth the test account and provide an access token but when you try to use graph api it will return unexpected errors. You may be alright if you are using web version vs native app setting in dev.facebook.com since supposedly you can create test users and associate them with the app but I haven't tried that.
Good Luck!