I am writing facebook interaction code in swift language for iOS. I have converted login and other code but stuck with sharing methods.
I am not able to find requestWithGraphPath method of FBRequest class in swift. If somebody know about this then please help me here. I have searched for solution on web but fail to find.
This is my sharing code in Objective-C
FBRequest *req=[FBRequest requestWithGraphPath:#"me/feed" parameters:params HTTPMethod:#"POST"];
[req startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error{
if (!error) {
// Sucess! Include your code to handle the results here
NSLog(#"Successful sharing");
} else {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(#"Error while sharing data");
}
}];
Thank you in advance.
Related
For an iOS app, using facebook sdk i need to fetch photos from user's album but i need to fetch them in a single request so that i could get info about albums and containing photos at the same time, for that i tried
/me/albums?fields=count,name,photos.limit(10){images}
that api call is working fine in Graph api explorer but not on iOS platform. I only need images field of photos that is why using
above api call
If i run this api it runs fine
/me/albums?fields=count,name,photos.limit(10)
only {images} part is causing the problem, the error message which i get is of unsupported url, have acquired the permissions for user_photos
Code :
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:#"/me/albums?fields=count,name,photos.limit(10){images}" parameters:nil HTTPMethod:#"GET"];
FBSDKGraphRequestConnection *connection = [[FBSDKGraphRequestConnection alloc] init];
[connection addRequest:request completionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if(!error) {
NSLog(#"result %#",result);
} else {
NSLog(#"error description : %#",error.description);
}
}];
[connection start];
I was making the final url call by adding/removing fields from graph api explorer side pane, the request call it was generating was
/me/albums?fields=count,name,photos.limit(10){images}
not working on iOS platform, but if i use this syntax instead
/me/albums?fields=count,name,photos.limit(10).fields(images)
to address fields of photos then it works fine, got the inspiration from answer posted here
I'm trying to do something that seems to be an order of magnitude more difficult than necessary.
I've got an iOS app that is written against a Parse backend. Our app's users can create items to store and they can sometimes generate alerts for these items.
I want to post a simple alert for a user to Facebook.
I've read quite a bit on the Facebook website about integrating Facebook into iOS, but their documentation is confusing and I've seen more than one person on StackOverflow mention that their iOS code is at least sometimes flawed.
Basically, the custom story will include the following items:
Story Title
Story Description (usually not very much text in here)
One or more pictures (I'd settle for 1, but I'd love to be able to post multiples)
If possible, a user-supplied GPS location.
I will admit up front that I'm a developer who is learning Facebook for work purposes, and I am far from being an expert on Facebook.
When I play around in the Facebook app, I can add a status update that can include:
Text
Picture(s)
Friends
What I'm doing
Where I am (or some location)
However, in the Facebook SDK, there appears to be only the following 2 options for posting a status update:
startForPostStatusUpdate:completionHandler:
startForPostStatusUpdate:place:tags:completionHandler:
If I'm missing something there, please let me know.
Secondly, I'm trying to follow Facebook's documentation and sample code to do the following sequence of events:
Upload and stage an image resource
Create an object (in my app, I've registered an "alert" object)
Create an action (in my app, I've registered a "post" action)
Here's the code that I've pieced together from Facebook's website (comments are mostly from other people's code, not my own):
- (void)postToFacebookWithAlert:(PFObject *)alert image:(UIImage *)image {
// Stage the image
[FBRequestConnection startForUploadStagingResourceWithImage:image completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (error != nil) {
// See: https://developers.facebook.com/docs/ios/errors
} else {
// Package image inside a dictionary, inside an array like we'll need it for the object
NSArray *image = #[#{#"url": [result objectForKey:#"uri"], #"user_generated" : #"true" }];
// Create an object
NSString *caption = // user-generate content
NSMutableDictionary<FBOpenGraphObject> *alert;
alert = [FBGraphObject openGraphObjectForPostWithType:#"<myapp>:alert"
title:caption
image:image
url:nil
description:alert[#"subtitle"]];
alert.provisionedForPost = YES;
// Post custom object
[FBRequestConnection startForPostOpenGraphObject:alert completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (error != nil) {
// An error occurred
} else {
NSMutableDictionary<FBGraphObject> *post = [FBGraphObject graphObject];
post[#"alert"] = result[#"id"];
[FBRequestConnection startForPostWithGraphPath:#"me/<myapp>:post" graphObject:post completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSLog(#"startForPostWithGraphPath:graphObject:completionHandler:");
if (error != nil) {
// An error occurred
NSLog(#"Encountered an error posting to Open Graph: %#", error);
} else {
NSLog(#"OG story posted, story id: %#", result[#"id"]);
}
}];
}
}];
}
}];
}
I've actually gotten this code to work one time. I'm logged in as my own personal Facebook account. If I go to my activity log, I can see the items that I'm trying to post. If I go to my photos, I can see the photos that I'm trying to upload. If I view my profile from my wife's app/account, it doesn't show up.
Does anyone have working code that does what I want?
Maybe you need to set "fb:explicitly_shared" to "true" and it should be reviewed by Facebook.
After your review pass, you can add the option like below.
[post setObject:#"true" forKey:#"fb:explicitly_shared"];
I have used FacebookSDK.framework for Facebook integration in my application. I have to like one facebook page from application. I have used following code for liking page.
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:#"https://www.facebook.com/demoappname"
, #"object",
nil
];
/* make the API call */
[FBRequestConnection startWithGraphPath:#"me/og.likes"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
)
{
NSDictionary *currentResult= [(NSArray *)[result data] objectAtIndex:0];
if(!error)
{
NSLog(#"there is no error");
}
else
{
NSLog(#"There is something wrong at here.");
}
}];
But I am not clear what I have to pass in "object" parameter. Can anybody help to what I am doing wrong at here.
Thanks,
If you read this documentation, it says-
The og.likes action can refer to any open graph object or URL, except for Facebook Pages or Photos.
So, liking a page with Graph API isn't possible.
The only thing you can do- add a Like Button to the page in your app.
I am trying to post dictionary to facebook in which image is attached, when user click on the image then should redirect the user to a link. I need to share the dictionary in the format shown in the attached image. If anybody knows that how can I achieve
the attached format then please let me know.
Please try this code , i also use this code for my app and resolve a issue ..
- (void)sendDataOnfacebook {
[self performPublishAction:^{
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:#"FASHMOD", #"name",
strFBPostUrl,#"link",
strFBPostTitle, #"message",
strFBPostImageUrl,#"picture",
#"Be a fashion model",#"description",nil];
[FBRequestConnection startWithGraphPath:#"me/feed"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection,id result,NSError *error)
{
NSLog(#"Shared successfully");
NSLog(#"status %# %# ",result,error);
}];
}];
}
I am working for an iOS app and I want to integrate Facebook sdk 3.1 for posting status on facebook but I really dont have any idea how to do it. Can anybody please provide me link to easy tutorials or step by step approach for how to do it.
To set up your Xcode project, read the instructions on the Facebook developer site.
You can create / open a session using [FBSession openActiveSessionWithAllowLoginUI:YES];
To publish to your timeline, you'll need to authorise with write permissions:
[[FBSession activeSession] reauthorizeWithPublishPermissions:#[ #"publish_stream" ] defaultAudience:FBSessionDefaultAudienceEveryone completionHandler:^(FBSession *authSession, NSError *authError) {
// If auth was successful, create a status update FBRequest
if (!authError) {
FBRequest *postRequest = [FBRequest requestForPostStatusUpdate:#"Hello, world!"];
[postRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
// TODO: Check for success / failure here
}];
}
}];
Try this:
[FBRequestConnection startForPostStatusUpdate:#"I've been through the storm, future, present and past.. Light as a feather, swift as a cat.. Clickety clack, clickety clack!!" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSLog(#"posted");
}];
Hope this helps.