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
Related
I am working on Dwolla payment gateway integration.
I have created one sandbox user and created one application and got Client key and secret both. Now if i am generating access token from sandbox account and using it(access token) in my iOS application it works fine and i am able to get balance,account info etc.
I want to generate access token from my iOS application but the method is not working on my side.
can any one help me for this.
I got dwolla sdks from here https://github.com/Dwolla/dwolla-ios .
According to this, This method should get called when user successful logged in
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)req navigationType:(UIWebViewNavigationType)navigationType
{
NSMutableURLRequest *request = (NSMutableURLRequest *)req;
NSArray *urlItems = [[request.URL query] componentsSeparatedByString:#"&"];
NSMutableArray *urlValues = [[NSMutableArray alloc] initWithCapacity:[urlItems count]];
for (int i = 0; i<[urlItems count]; i++)
{
NSArray *keysValues = [[urlItems objectAtIndex:i] componentsSeparatedByString:#"="];
[urlValues insertObject:keysValues atIndex:i];
}
if([urlValues count]>0 && [self hasCode:urlValues])
{
[self requestAccessToken:[[urlValues objectAtIndex:0]objectAtIndex:1]];
return NO;
}
return YES;
}
and this condition need to be full fill to get access token, but in my case this condition never gets true.
if([urlValues count]>0 && [self hasCode:urlValues])
{
[self requestAccessToken:[[urlValues objectAtIndex:0]objectAtIndex:1]];
return NO;
}
I use a facebook api to connect to facebook and send request via native dialogs provided by the api.
I followed the sample posted in the docs on developers.facebook.com
But I have following problem sending requests :
1. The requests are not shown in notifications - only in application center - In this case i think that it is a problem of that the app is in sandbox and not posted to APPSTORE
I succesfully send request to facebook server with right fbUser id. But when I want to receive the notification in app here comes the problem :
Following the docs as an authorized user I should se
this in open url method:
fb[APP_ID]://authorize#expires_in=[ACCESS_TOKEN_EXPIRATION]
&access_token=[USER_ACCESS_TOKEN]
&target_url=https://apps.facebook.com/[APP_NAME_SPACE]/?request_ids=
[COMMA_SEPARATED_REQUESTIDs]&ref=notif&app_request_type=user_to_user
But i can see only plain login without targer url .... I can see session expiration date, fb app id, access token and so on. But no target url?
So basically what the target_url is?
How it should be set?
What i have to include when sending request?
In addition :
application handle open url method is called properly.
checkRequests method is also called properly after app becomes active.
Please do not link me to the docs. I have read it moreless 50 times and didn't find any reasonable solution...
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// attempt to extract a token from the url
self.openedURL = url;
NSLog(#"%#",url);
return [FBSession.activeSession handleOpenURL:url];
}
- (void)sendRequest {
FBSBJSON *jsonWriter = [FBSBJSON new];
NSDictionary *gift = [NSDictionary dictionaryWithObjectsAndKeys:
#"5", #"points",
#"1", #"badge",
nil];
NSString *giftStr = [jsonWriter stringWithObject:gift];
NSMutableDictionary* params =
[NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Hi from test app", #"message",
giftStr, #"data",
nil];
[self.facebook dialog:#"apprequests"
andParams:params
andDelegate:self];
}
// Handle the request call back
- (void)dialogCompleteWithUrl:(NSURL *)url {
NSDictionary *params = [self parseURLParams:[url query]];
NSString *requestID = [params valueForKey:#"request"];
NSLog(#"Request ID: %#", requestID);
}
-(FBSession*)returnSession{
return self.session;
}
/*
* Helper function to get the request data
*/
- (void) notificationGet:(NSString *)requestid {
[FBRequestConnection startWithGraphPath:requestid
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
if (!error) {
NSString *title;
NSString *message;
if ([result objectForKey:#"data"]) {
title = [NSString
stringWithFormat:#"%# sent you a gift",
[[result objectForKey:#"from"]
objectForKey:#"name"]];
FBSBJSON *jsonParser = [FBSBJSON new];
NSDictionary *requestData =
[jsonParser
objectWithString:[result objectForKey:#"data"]];
message =
[NSString stringWithFormat:#"Badge: %#, Karma: %#",
[requestData objectForKey:#"badge"],
[requestData objectForKey:#"points"]];
} else {
title = [NSString
stringWithFormat:#"%# sent you a request",
[[result objectForKey:#"from"] objectForKey:#"name"]];
message = [NSString stringWithString:
[result objectForKey:#"message"]];
}
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:title
message:message
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil,
nil];
[alert show];
// Delete the request notification
[self notificationClear:[result objectForKey:#"id"]];
}
}];
}
/*
* Helper function to check incoming URL
*/
- (void) checkIncomingNotification {
if (self.openedURL) {
NSString *query = [self.openedURL fragment];
if (!query) {
query = [self.openedURL query];
}
NSDictionary *params = [self parseURLParams:query];
for (NSString * str in [params allKeys]) {
NSLog(#"key %#", str);
}
// Check target URL exists
NSString *targetURLString = [params valueForKey:#"target_url"];
if (targetURLString) {
NSURL *targetURL = [NSURL URLWithString:targetURLString];
NSDictionary *targetParams = [self parseURLParams:[targetURL query]];
NSString *ref = [targetParams valueForKey:#"ref"];
// Check for the ref parameter to check if this is one of
// our incoming news feed link, otherwise it can be an
// an attribution link
if ([ref isEqualToString:#"notif"]) {
// Get the request id
NSString *requestIDParam = [targetParams
objectForKey:#"request_ids"];
NSArray *requestIDs = [requestIDParam
componentsSeparatedByString:#","];
// Get the request data from a Graph API call to the
// request id endpoint
[self notificationGet:[requestIDs objectAtIndex:0]];
}
}
// Clean out to avoid duplicate calls
self.openedURL = nil;
}
}
Is there any way that these problems are caused by the way that the app is not published on Appstore (Appstore id is not set neither for iPhone nor iPad)?
Here are code snippets showing using of the fb api:
Thank you very much for the time.
Enable deep linking in Facebook app settings
Facebook sdk 3.5 requests not working
I think this link will help you,configure App on Facebook as well
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.
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!
I am using Graph API to get facebook user information as follows:
[facebook requestWithGraphPath:#"me" andDelegate:self];
How can I do this? I know that server response is in the form of JSON object but don't know how to parse it.
I don't find the links that helped me to resolve this issue.
This is the code I used (request:didLoad: is a FBRequestDelegate callback):
- (void)request:(FBRequest *)request didLoad:(id)result {
if ([result isKindOfClass:[NSDictionary class]]) {
NSDictionary* hash = result;
NSString *username = (NSString*)[hash valueForKey:#"name"];
[[NSUserDefaults standardUserDefaults] setObject:username forKey:#"Username"];
}
[self publishStream]; // publishStream is a custom methods of mine to create the post to publish
};
I remember that I read the FB ios api code and maybe this and this
I hope this works for you.
Bye,
Fran
I have answered this question here How to retrieve Facebook response using Facebook iOS SDK