I have a share button with following code:
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL fileURLWithPath:appFile];
FBSDKShareButton *shareButton = [[FBSDKShareButton alloc] init];
shareButton.shareContent = content;
shareButton.center = CGPointMake(60, 60);
And I see that my share button is greyed out. So I check my access token, which returns null:
NSString *fbAccessToken = [FBSDKAccessToken currentAccessToken].tokenString;
NSLog(#"fbAccessToken %#", fbAccessToken);
According to here, I need to call this first (I have implemented it inside my AppDelegate's - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions:
[[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions]
However, it returns NO, and according to FB's doc:
#abstract Call this method from the [UIApplicationDelegate
application:didFinishLaunchingWithOptions:] method of the AppDelegate
for your app. It should be invoked for the proper use of the Facebook
SDK.
#return YES if the url was intended for the Facebook SDK, NO if not.
I wonder why it returns NO that, perhaps, results my accessToken to be nil. Anyone can give me advise?
UPDATE:
I have logged-in, gained the token, allowed the permissions from my logged-in FB account, but the button is still greyed out.
For Android people need the native Facebook for Android app installed, version 7.0 or higher
Maybe it's the same thing on iOS.
Related
For some reason I keep getting an error for the AppInvite Dialog...
After setting up the info.plist for iOS9 by the documentation, setting all Facebook's parameters on the project, I get the error method being called with: Error Domain=com.facebook.sdk.core Code=9 "(null)".
App link was made on Facebook's Hosting API.
- (void) appInviteDialog:(FBSDKAppInviteDialog *)appInviteDialog didFailWithError:(NSError *)error{
NSLog(#"error: %#",error);
}
the method I use to invoke the dialog:
-(void)inviteFriends{
FBSDKAppInviteDialog* dia= [[FBSDKAppInviteDialog alloc] init];
if ([dia canShow])
{
FBSDKAppInviteContent *content =[[FBSDKAppInviteContent alloc] init];
content.appLinkURL = [NSURL URLWithString:self.applink];
content.appInvitePreviewImageURL = [NSURL URLWithString:self.preview_image];
[FBSDKAppInviteDialog showFromViewController:self.rootViewController.mainViewController withContent:content delegate:self];
}
[dia release];
return;
}
I tried calling inviteFriends in different places, but it won't start and would get to the didFailWithError method.
However, for some reason it may start working all of a sudden, and would work all the time ever since, unless the app is deleted from the device and reinstalled. In this case, it won't open again...
Make sure you have [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions]; in your AppDelegate. I've spend two days while trying to fix that.
Also make sure you have [FBSDKAppEvents activateApp];
in applicationDidBecomeActive:(UIApplication *)application
I'm trying to use the Facebook iOS Sharing SDK 4.1 but not getting a post off. I have an active session, but the following code does not post to my feed, and I do not get any of the callbacks either (success, error, or cancel), even though the caller is a FBSDKSharingDelegate. I have attempted to emulate the sample code in the SDK documentation but to no avail.
if ( [[FBSDKAccessToken currentAccessToken] hasGranted:#"publish_actions"] ) {
FBSDKShareLinkContent* content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = _Object.myPostServerURL;
content.contentDescription = _Object.myPostDescription;
content.contentTitle = #"New Post";
content.imageURL = _Object.coverArtServerURL;
BOOL ok = [[FBSDKShareAPI shareWithContent:content delegate:self] share];
}
I've tried with and without the "share" message wrapped around the shareWithContent; I can't tell from the documentation if it is required. Either way, no callbacks to delegate, no post. Can someone help me?
FBSDKShareLinkContent *tempContent=[[FBSDKShareLinkContent alloc] init];
tempContent.contentTitle=#"hello";
tempContent.contentDescription=#"desc";
tempContent.imageURL=[NSURL URLWithString:#"https://camo.githubusercontent.com/67212912f8d2d6a474d1af756603f7c13c837112/687474703a2f2f692e696d6775722e636f6d2f375976386d53412e676966"];
tempContent.contentURL=[NSURL URLWithString:#"https://scrumptious-facebook.parseapp.com/meals/italian/?fb_action_ids=10200411040395078&fb_action_types=fb_sample_scrumps%3Aeat"];
_shareAPI.delegate = self;
_shareAPI.shareContent = tempContent;
[_shareAPI share];
Also to use FBSDKShareAPI,You have to implement your for login and request for necessary permissions through u get FBSDKAccessToken,then only u can directly post to user feed.This is according to documentation of Facebook,If u want to show your own interface of sharing.
Currently may be your delgate may not work but might be ur app may face the issues of no access tokens and no permission issues
[[[FBSDKLoginManager alloc] init]
logInWithPublishPermissions:#[publish_actions]
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if ([result.grantedPermissions containsObject:publish_actions]) {
[_shareAPI share];
} else {
// This would be a nice place to tell the user why publishing
// is valuable.
}
}];
//Delegate methods
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results{
}
- (void)sharerDidCancel:(id<FBSDKSharing>)sharer{
}
- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error{
NSLog(#"%#",error);
}
You have to make some configuration in your appdelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
return [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];}
and
- (void)applicationDidBecomeActive:(UIApplication *)application {
[FBSDKAppEvents activateApp];
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.}
I am using zksforce SDK from here.
Every time when i starts my application it shows me login form. Instead of this I just want to maintain log in session till the user logs out.
Is it possible? What should I do for this? Following is my code that shows the log in form for salesforce.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
sectionViewController = [[SFT1SectionViewController alloc] init];
oAuthViewController = [[FDCOAuthViewController alloc] initWithTarget:sectionViewController selector:#selector(loginOAuth:error:) clientId:kSFOAuthConsumerKey];
oAuthViewController.modalPresentationStyle = UIModalPresentationFormSheet;
self.navigationController = [[UINavigationController alloc] initWithRootViewController:oAuthViewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
I also tried for custom login using loginWithUsername:password: method but it gives me token error saying that i should attach security token along with the password. what does that mean? I am calling method using following line :
[[FDCServerSwitchboard switchboard] loginWithUsername:usernameTextField.text password:passwordTextField.text target:rootViewController selector:#selector(loginResult:error:)];
This problem can also be solved by saving password when user logs in using web view. Is it possible to save password like this? If yes, how?
It looks like you might be missing the security token. It's appended to the end of the password.
This link explains how to generate the token
https://login.salesforce.com/help/doc/en/user_security_token.htm
NSString *password = #"Your password here";
NSString *token = #"your token here";
NSString *passwordToken = [NSString stringWithFormat:#"%#%#", password, token];
[[FDCServerSwitchboard switchboard] loginWithUsername:username password:passwordToken target:self selector:#selector(loginResult:error:)];
This would do. If you have forgot your token you can reset and the token will be sent to your email. You can do this through setup -> personal information -> reset token.
I have an iPhone app that allows users to record videos and I'd like them to be able to share those videos on Facebook.
However, unless the user decides to share, I don't want him/her to be redirected to Facebook. I've tried the method provided in the Facebook iOS tutorial, and it requires the user to be redirected to Facebook and authenticate as soon as the app starts up.
That's unnecessary.
What I'd like to do is have a "Share" button that allows the user to authenticate and then automatically upload a video right afterward using the POST request.
Is this possible? Has anyone achieved a similar effect?
Thanks.
I'm not sure which tutorial you're looking at, but it probably has you authenticate at launch just as a demo.
In your app, you can authorize you app with something like this after the video is saved
// Share button action
- (IBAction)sharePressed {
// If user is already authenticated
if ([facebook isSessionValid]) {
[self shareLinkToFacebook];
} else {
// Authenticate with just email permissions
NSArray* permissions = [NSArray arrayWithObjects:
#"email", nil];
[facebook setSessionDelegate:self];
[facebook authorize:permissions];
}
}
- (void) shareLinkToFacebook {
// Create a simple post
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
[params setValue:[video url] forKey:#"link"];
[params setValue:[video title] forKey:#"name"];
[params setValue:#"description" forKey:#"description"];
[facebook dialog:#"feed" andParams:params andDelegate:self];
}
// FBSessionDelegate
- (void) fbDidLogin {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:kFBAccessToken];
[defaults setObject:[facebook expirationDate] forKey:kFBExpirationDateKey];
[defaults synchronize];
[self shareLinkToFacebook];
}
You're going to have to authenticate with facebook to get an access key- there's no way around that.
You cannot do what you want. To publish something, you must have a valid access_token. the only way to achieve this is to follow the login procedure that you saw in the official example.
The answer to this question lies in creating a singleton that operates as both the FBSessionDelegate and the FBRequestDelegate, and allows you to pass one instance of Facebook around your program.
I called my singleton FacebookVideoUploader, and in my app delegate I called:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [[[FacebookVideoUploader sharedInstance] facebook] handleOpenURL:url];
That's it. This keeps the app delegate uncluttered and let's the singleton handle the delegate methods.
In my implementation file for my view controller that handles the video upload I put:
(IBAction)shareWithFacebook:(UIButton *)sender {
[[FacebookVideoUploader sharedInstance] postVideoToFacebook];
}
That's it. All of the delegate and session methods as well as postVideoToFacebook are handled in the FacebookVideoUploader singleton.
This allows my users to log into my app without being redirected to Facebook and lets them authenticate as soon as they decide they want to share a video.
UPDATE: I've realized that the below problem only occurs if the user has already given Facebook access to my app, and then reinstals my app. The first time the user selects the Facebook button in my app, it goes to the Facebook app to get authentication, but since the authentication status is still saved in the Facebook app, it returns immediately to my app without explanation to the user, and the postToFacebookWall method fails.
UPDATE 2: I ended up implementing the solution found here: How to authorize user through a DIALOG with the NEW Facebook Connect iOS API? and avoided the Facebook app. Safari is better because at least the user gets a message saying that they will be logging in. However the Feed Dialogue still fails the first time as before.
I'm having what must be a common problem, but I haven't been able to find the solution yet. Note that my app is restricted to iOS 5 and above.
I have an app with a Facebook button for posting to a users wall. When the button is pressed, the app will check to see if the user has already given permission to the app to post to the wall. If they have, a view pops up with a Feed Dialog with the wall post information. If they haven't, Safari will be opened and the user will be allowed to login. After logging in they will be taken back to the app and the Feed Dialog view will pop up.
This works on the Simulator, and on my device, if the Facebook app is not installed. If the Facebook app is installed, the user is taken to the Facebook app, but then immediately returned to the original app, without allowing the user to do anything. The Feed Dialog pops up, but it is completely blank and dismisses automatically. Pressing the Facebook button again will bring up the Feed Dialog view as it is supposed to once the user has given permission to the app to post to their wall.
I pretty much followed the instructions found here:
http://developers.facebook.com/docs/mobile/ios/build/#implementsso
and here:
http://developers.facebook.com/docs/reference/dialogs/feed/
In the AppDelegate I have the following code:
- (void)loginToFacebook
{
// Set up facebook
self.facebook = [[Facebook alloc] initWithAppId:#"YOUR_APP_ID" andDelegate:self];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:#"FBAccessTokenKey"]
&& [defaults objectForKey:#"FBExpirationDateKey"]) {
self.facebook.accessToken = [defaults objectForKey:#"FBAccessTokenKey"];
self.facebook.expirationDate = [defaults objectForKey:#"FBExpirationDateKey"];
}
if (![self.facebook isSessionValid]) {
[self.facebook authorize:nil];
}
}
// This is an FBSessionDelegate protocol method
// that gets called after a successful login
- (void)fbDidLogin
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[self.facebook accessToken] forKey:#"FBAccessTokenKey"];
[defaults setObject:[self.facebook expirationDate] forKey:#"FBExpirationDateKey"];
[defaults synchronize];
[[NSNotificationCenter defaultCenter] postNotificationName:#"POST_TO_FACEBOOK_WALL" object:nil];
}
// This is a UIApplicationDelegate protocol method
// It is called when safari is dismissed
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [self.facebook handleOpenURL:url];
}
The only difference between this and the sample code is that I added an NSNotification that is picked up by my view controller, where I have the following code:
- (void)facebookButtonPressed:(UIControl*)sender
{
Facebook *facebook = [(AppDelegate*)[[UIApplication sharedApplication] delegate] facebook];
if (![facebook isSessionValid])
{
// Login to facebook if not already logged in
[(AppDelegate*)[[UIApplication sharedApplication] delegate] loginToFacebook];
}
else
{
[self postToFacebookWall];
}
}
- (void)postToFacebookWall
{
Facebook *facebook = [(AppDelegate*)[[UIApplication sharedApplication] delegate] facebook];
/*Facebook Application ID*/
// TODO: Get this either from the AppDelegate facebook property or the info plist
NSString *client_id = #"YOUR_APP_ID";
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];
}
Does anyone know how to fix my issue? (Also, in case it isn't clear, YOUR_APP_ID is replaced with my app id in my code).
This sounds like an out-case in that it is this scenario of 'only when the app was installed, authed, then uninstalled, then reinstalled'.
You should be able to fall-back to "classic web view authentication" when this particular thing happens.
if (facebookAppDidNotReturnProperly) {
// therefore I must have been re-installed
// fallback to UIWebView
[facebook authorizeWithFBAppAuth:NO safariAuth:NO];
}
Then again, you could also use safari auth too I suppose.
I ended up solving my questions by implementing the two solutions found here:
https://stackoverflow.com/a/5683454/472344
https://stackoverflow.com/a/9137887/472344