Posting Screenshot of GameOver to FaceBook via Cocos2d - objective-c

I have searched a lot of forums and thread about posting screenshot on facebook. I have found the functon which is to be added in CCDirector which creates Screenshot. I have also seen the method which post the screenshot on facebook in an album or wall. But that is not working for me.
UIImage *tempImage = [[CCDirector sharedDirector] screenshotUIImage];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
tempImage,#"message",
nil];
[facebook requestWithGraphPath:#"me/photos"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
screenshotUIImage is the function that makes screenshot and it is working alright.
requestWithGraphPath does not do any thing for me. I have used different keywords in params like "tempImage, #"source"," and "tempImage, #"image"," but nothing happens.
However posting text on wall, like high score with predefined image link is working alright.
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
imageSrc, #"picture",
serverLink, #"link",
postName, #"name",
customMessage, #"caption",
nil];
// Post on Facebook.
[_facebook dialog:#"feed" andParams:params andDelegate:self];
Can any one guide me through how to do the picture posting?

In your params, you can try specifying a UIImage for the the key "picture":
UIImage *tempImage = [[CCDirector sharedDirector] screenshotUIImage];
NSMutableDictionary *params = [NSMutableDictionary dictionary];
[params setObject:myCaption forKey:#"caption"];
[params setObject:myMessage forKey:#"message"];
...
// UIImage object goes here
[params setObject:tempImage forKey:#"picture"];
[facebook requestWithGraphPath:#"me/photos" andParams:params andHttpMethod:#"POST" andDelegate:self];

Related

How to set default String from native ios app to facebook page from iphone app using dialog

below is my code
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"MyTestAPP", #"name",
#"http://myserver.com/", #"link",
#"My Post!", #"caption",
#"ValuedCommunity", #"description",
myMessage, #"message",
nil];
// Publish.
[facebook dialog:#"feed" andParams:params andDelegate:self];
Now with this code when I click on publish button I get this
I have tried graph api using the below code but it gave me an error msg of "facebookerrdomain error 10000".
[facebook requestWithGraphPath:#"me/feed" andParams:params andHttpMethod:#"POST" andDelegate:self];
Now What I want to do is, want to set "myMessage" text instead of Say Something about this.
Is it possible to do so??
If yes then how can I achieve it.
Please Advice
Thanks
Everything is possible. Use requestWithGraphPath:andParams:andHttpMethod:andDelegate: method and set permission as publish_stream, then you will get message.
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
yourMessage,#"message",nil];
NSString *user_selected = [NSString stringWithFormat:#"me/feed"];
[facebook requestWithGraphPath:user_selected andParams:params andHttpMethod:#"POST" andDelegate:self];
Hi Every1 I was Trying to solve this from past 2 days And How I solved
add One more parameter named access_token in NSMutableDictionary's param object like this
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Ahha", #"name",
#"http://vctestserver.com/", #"link",
#"VCAHHA", #"caption",
#"ValuedCommunity", #"description",
storyTwtFB, #"message",
accessToken,#"access_token",
nil];
[facebook requestWithGraphPath:#"me/feed" andParams:params andHttpMethod:#"POST" andDelegate:self];
Where I got accessToken's Value from delegate mathod [facebook accessToken]. and storyTwtb is my application's String that I wanted to post on facebook.

IOS Fb wall post method not working

I am using following code. It takes me to FB Dialog box where I authorize the app and after authorizing app it takes me back to my applicaiton. However It NEVER post anything on the wall.
Any ideas what is wrong?
- (void) login
{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.facebook = [[Facebook alloc] initWithAppId:#"MY_APP_ID" andDelegate:self];
NSArray* permissions = [NSArray arrayWithObjects:#"publish_stream", nil];
[appDelegate.facebook authorize:permissions];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#".", #"name",
#".", #"caption",
nil];
/*
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#".", #"name",
#"Build great social apps and get more installs.", #"caption",
#"The Facebook SDK for iOS makes it easier and faster to develop Facebook integrated iOS apps.", #"description",
#"https://developers.facebook.com/ios", #"link",
#"https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png", #"picture",
nil];
*/
// Invoke the dialog
[appDelegate.facebook dialog:#"feed" andParams:params andDelegate:self];
}
You should do it like this:
graphPath = #"me/feed";
[params setObject:#"link" forKey:#"type"];
[params setObject:pict forKey:#"picture"];
[params setObject:self.url forKey:#"link"];
[params setObject:self.message forKey:#"message"];
[params setObject:self.urlName forKey:#"name"];
[params setObject:self.caption forKey:#"caption"];
[params setObject:self.urlDescription forKey:#"description"];
[appDelegate.facebook requestWithGraphPath:graphPath andParams:params andHttpMethod:#"POST" andDelegate:self];

Issue with Facebook feed dialog

I'm trying implement a Facebook dialog feed, but it doesn't show anything. I have followed :
Post to user's Facebook wall with iPhone using latest FBConnect SDK
and:
http://developers.facebook.com/docs/reference/dialogs/feed/
Here is my code:
-(void) facebookPost{
NSString *kAppId = [[NSString alloc] initWithString:#"383032031757454"];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
kAppId, #"app_id",
#"http://developers.facebook.com/docs/reference/dialogs/", #"link",
#"http://fbrell.com/f8.jpg", #"picture",
#"Facebook Dialogs", #"name",
#"Reference Documentation", #"caption",
#"Using Dialogs to interact with users.", #"description",
nil];
[facebook dialog:#"feed" andParams:params andDelegate:self];
}
Many thanks for your help.
Froi
i think u have to set accessToken like below
[params setObject:facebook.accessToken forKey:#"access_token"];
[facebook dialog:#"feed" andParams:params andDelegate:self];

Facebook iPhone SDK - automatically PublishSteam (bypass Post to wall dialog)

Trying to implement facebook wall post on the iphone app I'm working on.
How can I bypass the "Post to Your Wall" dialog box and just submit straight?
Basically I'm just trying to post a url and I don't really want to allow people to see that "Write something" textbox.
Here is the code that I have so far (from the sample app).
SBJSON *jsonWriter = [[SBJSON new] autorelease];
NSDictionary* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:
#"Always Running",#"text",#"http://itsti.me/",#"href", nil], nil];
NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];
NSDictionary* attachment = [NSDictionary dictionaryWithObjectsAndKeys:
#"a long run", #"name",
#"The Facebook Running app", #"caption",
#"it is fun", #"description",
#"http://itsti.me/", #"href", nil];
NSString *attachmentStr = [jsonWriter stringWithObject:attachment];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Share on Facebook", #"user_message_prompt",
actionLinksStr, #"action_links",
attachmentStr, #"attachment",
nil];
[_facebook dialog:#"feed"
andParams:params
andDelegate:self];
Thank you,
Tee
Just use one of the - (FBRequest*)requestWith... instance methods of the Facebook class.
Simple wall post using the old REST API:
NSString *facebookStatusMessage = #"facebookStatusMessage";
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
facebookStatusMessage, #"status",
nil];
FBRequest *request = [_facebook requestWithMethodName:#"status.set" andParams:params andHttpMethod:#"POST" andDelegate:self];
It's better to use the Facebook Graph API with - (FBRequest*)requestWithGraphPath: as the REST API will get deprecated.
Then also implement some of the FBRequestDelegate protocol:
- (void)request:(FBRequest *)request didFailWithError:(NSError *)error {
}
- (void)request:(FBRequest *)request didLoad:(id)result {
// result may be a dictionary, an array, a string, or a number,
// depending on the format of the API response
}

Facebook Graph API Upload Photo Problem

I've searched all through the web and have downloaded the Facebook SDK thing to try out the upload photo function and it worked there.
Exact same codes over to my application and it doesn't work.
Help please???
These are my codes:
- (IBAction)pushUpload:(id)sender {
NSString *path = #"http://www.facebook.com/images/devsite/iphone_connect_btn.jpg";
NSURL *url = [NSURL URLWithString:path];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
img, #"picture",
nil];
[_facebook requestWithGraphPath:#"me/photos"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
[img release];
[loadingIcon startAnimating];
}
As you can see I've placed the loadingIcon there to start animating when its uploading.. and at the request didload i did the stopanimating command when it has successfully uploaded.
-(void)request:(FBRequest *)request didLoad:(id)result{
[loadingIcon stopAnimating];
if ([result isKindOfClass:[NSArray class]]) {
result = [result objectAtIndex:0];
}
if ([result objectForKey:#"owner"]) {
[loadingIcon stopAnimating];
UIAlertView *alert;
alert = [[UIAlertView alloc] initWithTitle:#""
message:#"Photo uploaded."
delegate:self cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
[alert release];
} else {
// [self.label setText:[result objectForKey:#"name"]];
}
}
The thing is, the loading icon just keeps animating and no errors and all but still no picture uploaded to my facebook account. Any ideas why??
This are the codes in my .h file:
#interface UploadPhotosViewController :
UIViewController(FBRequestDelegate, FBDialogDelegate,
FBSessionDelegate){
IBOutlet UIImageView *imageView;
IBOutlet UIActivityIndicatorView *loadingIcon;
IBOutlet UIBarButtonItem *_pushPick;
IBOutlet UIBarButtonItem *_pushUpload;
Facebook * _facebook; }
#property(readonly) Facebook *facebook;
(IBAction)pushUpload:(id)sender;
(IBAction)pushPick:(id)sender;
//UINavigationControllerDelegate, UIImagePickerControllerDelegate,
#end
Another thing to note is that there are no colors indicator for the (FBRequestDelegate, FBDialogDelegate, FBSessionDelegate) when there are supposed to be.. is it a problem?
Check if you have written delegates of Facebook in your .h file.
Also check this code
It worked for me..
NSString *string=#"Images of me";
SBJSON *jsonWriter = [[SBJSON new] autorelease];
NSDictionary* attachment = [NSDictionary dictionaryWithObjectsAndKeys:
#"My name", #"name",
string, #"description", nil];
NSString *attachmentStr = [jsonWriter stringWithObject:attachment];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"This is image",#"description",
#"Share on Facebook", #"user_message_prompt",
//actionLinksStr, #"action_links",
attachmentStr, #"attachment",
/*Your image here", #"picture",
nil];
Try this code
Hope it helps....
Try me/feed instead of me/photos.
[_facebook requestWithGraphPath:#"me/feed"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
I think it is because you're not declaring your protocols correctly. They go in angle brackets, not in parenthesis.
#interface UploadPhotosViewController : UIViewController<FBRequestDelegate, FBDialogDelegate, FBSessionDelegate>