Is user_photos needed? - ios

Please excuse the elementary question but I am pretty confused on requesting Facebook permissions for my app. My app allows users to select photos then login to their facebook page and those photos are posted on their timeline. I am requesting manage_pages, publish_pages, and publish_actions. In my developer account I added two testers who are friends of mine and we thoroughly tested the process. Everything works perfectly. But when I created a Test User (the one where facebook creates a generic account) my app doesn't post photos to their wall. I granted the test user the same permissions. I am now wondering if I need to call user_photos as another requested permission. I don't think I do since I am not requesting access to the users photos or albums. I am simply posting photos to their timeline which I thought is what publish_pages and publish_actions does. Can you look at the code and see if you can find what I am doing wrong?
- (IBAction)facebookButtonClicked1:(id)sender
{
if ([self.selectedImages count] > 0)
{
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
login.loginBehavior = FBSDKLoginBehaviorWeb;
[login logInWithPublishPermissions:#[#"publish_actions"]
fromViewController:self
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
NSLog(#"Process error");
} else if (result.isCancelled) {
NSLog(#"Cancelled");
} else {
NSLog(#"Logged in");
[self shareSegmentWithFacebookComposer];
}
}];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"No Photos" message:#"You have not selected any photo." delegate:self cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alert show];
}
}
-(void)shareSegmentWithFacebookComposer{
if ([[FBSDKAccessToken currentAccessToken] hasGranted:#"publish_actions"]) {
[self publishFBPost]; //publish
} else {
NSLog(#"no publish permissions");
}
}
-(void) publishFBPost{
NSMutableArray* photos = [[NSMutableArray alloc] init];
for (NSString* imageFile in self.selectedImages) {
UIImage *image = [UIImage imageWithContentsOfFile:[dataPath stringByAppendingPathComponent:imageFile]];
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
photo.image = image;
photo.userGenerated = YES;
[photos addObject:photo];
}
FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
content.photos = [photos copy];
[FBSDKShareDialog showFromViewController:self
withContent:content
delegate:nil];
[FBSDKShareAPI shareWithContent:content delegate:nil];
viewThanks.hidden = NO;
[NSTimer scheduledTimerWithTimeInterval:4.5 target:self selector:#selector(start) userInfo:nil repeats:NO];
FBSDKShareDialog *shareDialog = [FBSDKShareDialog new];
[shareDialog setMode:FBSDKShareDialogModeAutomatic];
[shareDialog setShareContent:content];
[shareDialog show];
}

There were publish_stream permission to upload photos but in the latest SDK publish_actions have replaced publish_actions so you only need publish_actions. And if you want to see the user's photos then you need the user_photos permission.

Related

using Twitter SDK to send tweet failed, but I'dont know why

I'm using Twitter SDK to loggin and tweet. Authenticate it's ok, but when use TWTRComposer with a simple text, the SDK callback return 'TWTRComposerResultDone', but the Simulator/Device show 'The tweet "text" cannot be sent because the connection to Twitter failed.
The debugger show 'plugin com.apple.share.Twitter.post invalidated' but everything aparently is correct.
Is there a bug or I forgot some thing.
My code:
TWTRComposer *composer = [[TWTRComposer alloc] init];
[composer setText:#"some text"];
[composer showWithCompletion:^(TWTRComposerResult result) {
if (result == TWTRComposerResultCancelled) {
NSLog(#"Tweet composition cancelled");
}
else {
NSLog(#"Sending Tweet!");
}
}];
Tweet Using SDK
1. Crearte App on twitter.developer
2. add twitter frameworks like TwitterCore.framework, TwitterKit.framework, Fabric.framework, TwitterKitResources.bundle
3. write below code in tweet button
[[Twitter sharedInstance] startWithConsumerKey:#"YourConsumerKey" consumerSecret:#"YourConsumerSecret"];
[Fabric with:#[[Twitter sharedInstance]]];
[[Twitter sharedInstance] logInWithCompletion:^(TWTRSession *session, NSError *error)
{
if (session)
{
NSLog(#"logged in user with id %#", session.userID);
TWTRComposer *composer = [[TWTRComposer alloc] init];
[composer setText:#"Enter Your Tweet Message"];
//[composer setImage:[UIImage imageNamed:#"fabric"]];
[composer showFromViewController:self completion:^(TWTRComposerResult result) {
if (result == TWTRComposerResultCancelled)
{
NSLog(#"Tweet composition cancelled");
}
else
{
NSLog(#"Sending Tweet!");
UIAlertView *warningAlert = [[UIAlertView alloc] initWithTitle:#"" message:#"Sent Tweet!" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[warningAlert show];
}
}];
}
else
{
// log error
}
}];

How to upload an image on Facebook without staging it in iOS?

This is my code so far to post a custom story with a local Image. The Image shows in the Share Dialog but the post doesn't complete.
NSMutableDictionary<FBOpenGraphObject> *object = [FBGraphObject openGraphObjectForPost];
object.provisionedForPost = YES;
object[#"title"] = #"";
object[#"type"] = #"socialsnooker:game_of_snooker";
object[#"description"] = #"";
object[#"url"] = #"http://socialsnooker.com/opengraph.php";
object[#"image"] = #[#{#"url": newImage, #"user_generated" : #"false" }];
NSArray* images = #[#{#"url": newImage, #"user_generated" : #"true" }];
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
[action setObject:images forKey:#"image"];
[action setObject:object forKey:#"game_of_snooker"];
[action setTags:#[opponent]];
// Tag a place using the place's id
id<FBGraphPlace> place = (id<FBGraphPlace>)[FBGraphObject graphObject];
[place setObjectID:#"36397646443"]; // Q-Masters
[action setPlace:place];
// Check if the Facebook app is installed and we can present the share dialog
FBOpenGraphActionParams *params = [[FBOpenGraphActionParams alloc] init];
params.action = action;
params.actionType = #"socialsnooker:score";
// If the Facebook app is installed and we can present the share dialog
if([FBDialogs canPresentShareDialogWithOpenGraphActionParams:params]) {
// Show the share dialog
[FBDialogs presentShareDialogWithOpenGraphAction:action
actionType:#"socialsnooker:score"
previewPropertyName:#"game_of_snooker"
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(#"Error publishing story: %#", error.description);
} else {
// Success
NSLog(#"result %#", results);
}
}];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"App Not Installed"
message:#"The Facebook App couldn't be found on your phone."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
Here is a Screenshot of the Share Dialog
The Image does show up in the Share Dialog and I do get a post ID in return but the action does not get posted on Facebook.
Any help would be greatly appreciated. Thanks.

Redirect to Settings Screen for Twitter Login

In Twitter ,if User has Logged In in the Twitter Account in Settings Screen It will allow to post.Or Else it will display a Alert as "No Twitter Accounts" with 2 Options "Settings" and "Cancel". If Cancel is Tapped it will close alert and reject post to twitter. And if Settings is Tapped it is not redirecting to Settings Screen.
Also i used
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"prefs:root=TWITTER"]];
But No Luck. As far as i checked all are saying as from iOS 5.1 it wont work.But i see some apps still redirecting to settings screen in iOS7. Is it possible to redirect in iOS7.
Thanks in Advance.
You can use below code in your login button's action:
if ([TWTweetComposeViewController canSendTweet])
{
//yes user is logged in
accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
// Request access from the user to use their Twitter accounts.
[accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error)
{
// Did user allow us access?
if (granted == YES)
{
// Populate array with all available Twitter accounts
NSArray *arrayOfAccounts = [accountStore accountsWithAccountType:accountType];
ACAccount *acct = [arrayOfAccounts objectAtIndex:0];
// Set the cell text to the username of the twitter account
NSString *userID = [[acct valueForKey:#"properties"] valueForKey:#"user_id"];
TwitterIdStr = [[NSString alloc] initWithString:userID];
FbIdStr = [[NSString alloc] init];
NSLog(#"%#",userID);
NSString *networkCheck = [[NSUserDefaults standardUserDefaults] valueForKey:#"isNetWorkAvailable"];
if ([networkCheck isEqualToString:#"NotConnected"])
{
// not connected
dispatch_async(dispatch_get_main_queue(), ^{
// Display/dismiss your alert
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"No network connection" message:#"You must be connected to the internet to proceed." delegate:nil cancelButtonTitle:#"OK"otherButtonTitles:nil];
[alert show];
});
} else
{
fNameStr = [[NSString alloc] init];
lNameStr = [[NSString alloc] init];
emailStr = [[NSString alloc] init];
[self startProgressViewAgain];
}
}
}];
}
else
{
//show tweeet login prompt to user to login
TWTweetComposeViewController *viewController = [[TWTweetComposeViewController alloc] init];
//hide the tweet screen
viewController.view.hidden = YES;
//fire tweetComposeView to show "No Twitter Accounts" alert view on iOS5.1
viewController.completionHandler = ^(TWTweetComposeViewControllerResult result) {
if (result == TWTweetComposeViewControllerResultCancelled) {
[self dismissModalViewControllerAnimated:NO];
}
};
[self presentModalViewController:viewController animated:NO];
//hide the keyboard
[viewController.view endEditing:YES];
}

Facebook ios sdk 3 crash when try to use FBSessionLoginBehaviorForcingWebView

I am using facebook sdk 3 with ios 5. I want to ask login window each time to user. Expect different users use app. I tried below code. It show login in a popover view inside app not with safari. But after I login or close window app crash.
NSArray *permissions = [NSArray arrayWithObjects:#"publish_actions", #"user_photos", nil];
FBSessionLoginBehavior behavior = FBSessionLoginBehaviorForcingWebView;
FBSessionTokenCachingStrategy *tokenCachingStrategy = [[FBSessionTokenCachingStrategy alloc]
initWithUserDefaultTokenInformationKeyName:#"FBTest"];
FBSession *session = [[FBSession alloc] initWithAppID:#"Appid"
permissions:permissions
urlSchemeSuffix:nil
tokenCacheStrategy:tokenCachingStrategy];
[session openWithBehavior:behavior
completionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
// this handler is called back whether the login succeeds or fails; in the
// success case it will also be called back upon each state transition between
// session-open and session-close
if (error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Error"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
NSLog(#"SUCEEES");
[self sessionStateChanged:session state:session.state error:error];
}];
FBLoginView *loginview = [[FBLoginView alloc] init];
loginview.frame = CGRectOffset(loginview.frame, 5, 5);
loginview.delegate = self;
[self.view addSubview:loginview];
[loginview sizeToFit];
This will ask for the login window each time

What should i do, when user cant send message to twitter

I got app, which can send twits.
I do it in this way:
- (IBAction)twitDream:(id)sender
{
if ([TWTweetComposeViewController canSendTweet]) {
TWTweetComposeViewController *tweet =
[[TWTweetComposeViewController alloc] init];
if (dream.image != [UIImage imageNamed:#"blank-photo.png"])
[tweet addImage:dream.image];
NSString *twitMsg = [dreamField.text stringByAppendingString:#" send via Dreamer"];
[tweet setInitialText:twitMsg];
[self presentModalViewController:tweet animated:YES];
} else {
//can't tweet!
}
}
What should i do when [TWTweetComposeViewController canSendTweet] is equal to NO ? And when it is equal to NO ?
That is full solution code:
- (IBAction)twitDream:(id)sender
{
if ([TWTweetComposeViewController canSendTweet]) {
TWTweetComposeViewController *tweet =
[[TWTweetComposeViewController alloc] init];
if (dream.image != [UIImage imageNamed:#"blank-photo.png"]) {[tweet addImage:dream.image];}
NSString *twitMsg = [dreamField.text stringByAppendingString:#" #Dreamer"];
[tweet setInitialText:twitMsg];
[self presentModalViewController:tweet animated:YES];
} else {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:#"Sorry"
message:#"You can't send a tweet right now, make sure your device has an internet connection and you have at least one Twitter account setup"
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
}

Resources