Multiple requestWithGraphPath Facebook iOS - iphone

Maybe a simple question but I can't seem to get it. I want to get the users profile picture but also want search his/her posts. Like this:
[facebook requestWithGraphPath:#"me/picture?type=large" andDelegate:self];
[facebook requestWithGraphPath:#"me/home?q=TEST" andDelegate:self];
I can get the picute out with the following code:
- (void)request:(FBRequest*)request didLoad:(id)result{
if ([result isKindOfClass:[NSData class]])
{
UIImage *image = [[UIImage alloc] initWithData:result];
UIImageView *profilePicture = [[UIImageView alloc] initWithImage:image];
[image release];
profilePicture.frame = CGRectMake(20, 20, 80, 80);
[self.view addSubview:profilePicture];
[profilePicture release];
}
}
But I don't know how i can get the search query data out.
Any help would be great! Thnx

requestWithGraphPath:andDelegate: returns a pointer to an object of type FBRequest. Save it and use it later to differentiate between requests in request:didLoad: comparing it against the first parameter passed to this method.
For example, you can have two properties to hold the request objects. Although, if you are going to deal with many requests, you can use a container like NSDictionary instead.
self.pictureRequest = [facebook requestWithGraphPath:#"me/picture?type=large" andDelegate:self];
self.homeRequest = [facebook requestWithGraphPath:#"me/home?q=TEST" andDelegate:self];
And then in request:didLoad::
- (void)request:(FBRequest*)request didLoad:(id)result {
if (request == self.homeRequest) {
// ...
} else if (request == self.pictureRequest) {
// ...
}
}

Related

Method is not getting called twice in IOS

I am working on Instagram integration in IOS.Every thing goes well.I am geting the feeds of the user and displaying them on tableview and also in scroll view.Here the user is allowed to refresh the page.While refreshing the method is not getting called and its getting crashed because of zero objects in array.I had used the following code to call the method.
-(IBAction)loginAction:(id)sender
{
AppDelegate* appDelegate_new = (AppDelegate*)[UIApplication sharedApplication].delegate;
[appDelegate_new.instagram authorize:[NSArray arrayWithObjects:#"comments", #"likes", nil]];
if ([appDelegate.instagram isSessionValid]) {
// NSLog(#"ViewDidLoad Session Valid");
loginView.hidden=YES;
crossButton.hidden=YES;
settingsButton.hidden=NO;
noticeView.hidden=YES;
[self.view addSubview:feedsView];
// [self.logOutView removeFromSuperview];
self.feedsView.frame=CGRectMake(0, 0, 240, 300);
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:#"users/self/feed", #"method", nil];
[appDelegate.instagram requestWithParams:params
delegate:self];
}
}
The called method was like this
- (void)request:(IGRequest *)request didLoad:(id)result
{
[self performSelector:#selector(startspinner) withObject:nil afterDelay:0.1];
self.data = (NSMutableArray *)[result objectForKey:#"data"];
// NSLog(#"Data Count is %#",[self.data description]);
createdArray=[[NSMutableArray alloc]init];
//*****Here I am performing Json Parsing******//
}
I am calling the above request method again while refreshing
- (void)dropViewDidBeginRefreshing:(ODRefreshControl *)refreshControl
{
[createdArray removeAllObjects];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:#"users/self/feed", #"method", nil];
[appDelegate.instagram requestWithParams:params
delegate:self];
[self performSelector:#selector(refreshData) withObject:nil afterDelay:5.0];
}
Please tell me where I am going wrong.Correction appreciated.Thanks in advance.
Try it....
[NSTimer scheduledTimerWithTimeInterval:0.5f
target:self
selector:#selector(showTime)
userInfo:NULL
repeats:YES];
- (void)showTime
{
NSLog(#"Method called");
}
Use NSTimer for call method frequently.
Hope i helped.

Iphone app facebook connection?

hello i have a app that connects and post to user wall but when i try to post it always open the persmission page and in that page it writes you already give permission to this app.I want it to come only 1 time can anyone help me to do that?
- (id)init {
if (self == [super init]) {
facebook = [[Facebook alloc] initWithAppId:kAppId];
facebook.sessionDelegate = self;
if(permissions==nil){
permissions = [[NSArray arrayWithObjects:
#"read_stream", #"user_birthday",
#"publish_stream", nil] retain];
}
[self login];
}
return self;
}
- (void)login {
if (![_session isConnected]) {
[self postToWall];
}
// only authorize if the access token isn't valid
// if it *is* valid, no need to authenticate. just move on
if (![facebook isSessionValid]) {
[facebook authorize:permissions delegate:self];
}
is it because i init method?
See this page - https://developers.facebook.com/docs/guides/mobile/. Basically what you want to do is save the authentication information (access_token) when the user is authorized, then next time you can check for the saved values and skip the authentication.

How to do wall post on facebook with image stored on iPhone?

I have an application in which i have to post image on Wall of facebook.
Now problem is i used GraphAPI facebook and i have to pass link of photo but i have photo in my iPhone and not on any server.
So how do i post wall with image and other parameters without URL of image?
You may use NSURLConnection ASIHttpRequest library for downloading the images from a url.
You will have to do the following:
1. Create a NSUrlConnection and implement the delegate methods
2. Pass the url in your request and you will get the data in -(void)connectionDidFinishLoading: (NSURLConnection *)connection
3. You can then create a UIImage from this data using UIImage *image = [[UIImage alloc] initWithData:activeDownloadData];
FBStreamDialog *dialog = [[[FBStreamDialog alloc] init] autorelease];
dialog.userMessagePrompt = #"Enter your message:";
NSDictionary *params = nil;
[[FBRequest requestWithDelegate:self] call:#"facebook.photos.upload" params:params dataParam:(NSData*)wallImage];
[dialog show];
Edit:
--
Actually, posting an image to the Facebook wall has to be from the web. So you will have to upload the image first; maybe try a 3rd party service like twitpic or something, return the response url and place it in your params.
--
You can use the following to post with image to Facebook. You can also replace UIImage with a physical URL as well.
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
kAppID, #"app_id",
#"http://bit.ly/dDZQXt", #"link",
#"www.has.to.be.web.based.com", #"picture",
EasyStrings(#"Mobile Profiles for ",device), #"name",
EasyStrings(#"Current Profile: ",currProfile), #"caption",
#"I am using Mobile Profiles for iPhone, iPod touch and iPad.", #"description",
message, #"message",
nil];
[_facebook dialog:#"feed"
andParams:params
andDelegate:self];
What it will look like:
The house icon is loaded from [UIImage imageNamed:#"something.png"].
I modified the facebook demo app. It uses the modal view to select a picture from your phone. You can use this code, granted you must add two buttons (i.e., selectPicture button and a uploadPhoto button) -- also be sure to add to UIViewController in the .h file:
/**
* Upload a photo.
*/
- (IBAction)uploadPhoto:(id)sender {
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
image, #"picture",
nil];
[_facebook requestWithGraphPath:#"me/photos"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
}
/**
* Select a photo.
*/
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
image = [info objectForKey:UIImagePickerControllerOriginalImage];
[self dismissModalViewControllerAnimated:YES];
}
- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissModalViewControllerAnimated:YES];
}
- (IBAction) selectPicture:(UIButton *)sender;
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
[self presentModalViewController:picker animated:YES];
[picker release];
}
Try using BMSocialShare which is a simple lib I wrote. It is exactly doing what you want. Upload some local image (and even open a dialog for the user to add a comment) to the user's wall:
BMFacebookPost *post = [[BMFacebookPost alloc] initWithImage:[UIImage imageNamed:#"image.png"]];
[[BMSocialShare sharedInstance] facebookPublish:post];

facebookErrDomain error 10000 when calling graph api Facebook ios

I'm struggling with the graph api for a few days now and I can't seem to get any further.
In my appdelegate i've placed the following code within the didFinishLaunching
facebook = [[Facebook alloc] initWithAppId:#"cut-app-id-out"];
NSArray* permissions = [[NSArray arrayWithObjects:
#"email", #"user_location", #"user_events", #"user_checkins", #"read_stream", nil] retain];
[facebook authorize:permissions delegate:self];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"test message from stackoverflow", #"message",
nil];
[facebook requestWithGraphPath:#"/me/feed" andParams:params andDelegate:self];
as you can see i'm trying to get the users feed out. I use the following code to place the data into a proper dictionary.
- (void)request:(FBRequest*)request didLoad:(id)result
{
if ([result isKindOfClass:[NSDictionary class]]) {
NSLog(#"count : %d ", [result count]);
NSArray* resultArray = [result allObjects];
NSLog(#"count : %d ", [result count]);
result = [resultArray objectAtIndex:0];
NSLog(#"count : %d ", [result count]);
result = [result objectAtIndex:0];
}
}
But the didFailWithError: function gives me the following error:
The operation couldn’t be completed. (facebookErrDomain error 10000.)
I've place the FBRequestDelegate in my interface file as following:
#interface TabbedCalculationAppDelegate : NSObject
<FBRequestDelegate>{
Is there something what i'm missing?
There's a lot more needed to handle Facebook responses, especially after authorization. You're not going to be able to make calls against the Facebook API immediately after the authorize method. Please see their sample code which shows how to respond to the various events which you will need to do, most importantly the fbDidLogin and fbDidNotLogin ones. Only once you have a successful login should you access the Graph API.
In addition, it looks like you're trying to post a message with the Graph API. Unfortunately that's not the way to do it and a call like [facebook requestWithGraphPath:#"me/feed" andDelegate:self]; is meant for read-only use. Again, look at the above link for an example of how to use the publish_stream permission (their code has a publishStream example method).

FBConnect : send some images on somebody's wall

I found out how to send some text on the user's wall, with the FBConnect API, on iphone.
I even found how to put an image already on the internet :
FBFeedDialog* dialog = [[[FBFeedDialog alloc] init] autorelease];
dialog.delegate = self;
dialog.templateBundleId = 12345;
dialog.templateData = #"{\"image\":[{\"src\":\"http://sample.png\",\"href\":\"http://sample.com\"}] }";
[dialog show];
(see http://wiki.developers.facebook.com/index.php/Facebook_Connect_for_iPhone)
But I can't figure out how to upload an UIImage from my iphone to the user's wall with FB Api.
Do I have, first, to upload the image on any website, then put its url in the templateData ?
Isn't there any simpler solution ?
Thanks.
Martin
Use the below function to upload the image, pass the UIImage as the parameter, it will work.
- (void)uploadPhoto:(UIImage *)uploadImage
{
NSMutableDictionary *args = [[[NSMutableDictionary alloc] init] autorelease];
[args setObject:uploadImage forKey:#"image"]; // 'images' is an array of 'UIImage' objects
[args setObject:#"4865751097970555873" forKey:#"aid"];// this should be album id
uploadPhotoRequest = [FBRequest requestWithDelegate:self];
[uploadPhotoRequest call:#"photos.upload" params:args];
NSLog(#"uploading image is successful");
}
[[FBRequest requestWithDelegate:self] call:#"facebook.photos.upload" params:params dataParam:(NSData*)img;
and pass params to nil . it will upload image to default album