UIActionSheet problem with FBConncet {iPhone SDK} - iphone

i implement FBConnect for my app via UIActionSheet with 2buttons .
my buttons are "Share On Facebook" and "Log out from facebook" . so i want when user click on share on facebook button FBLoginDialog shows and user log in to facebook with his account and then show FBStreamDial appears and user share something on his wall . and never show FBLoginDialog again . it means just one time . and when user going to log out that method repeat again .
How can mange it ?
if i use this method : 2 method appear together !
-(void)actionSheet:(UIActionSheet *)menu didDismissWithButtonIndex:(NSInteger)buttonIndex {
switch (buttonIndex) {
case 0:
///SHOW LOGIN WINDOW
NSLog(#"asdasda");
FBLoginDialog* dialog = [[[FBLoginDialog alloc] initWithSession:session] autorelease];
[dialog show];
///SHOW FBStreamDialog
FBStreamDialog* dialog2 = [[[FBStreamDialog alloc] init] autorelease];
dialog2.delegate = self;
dialog2.userMessagePrompt = #"Share Ghazals on your wall";
dialog2.attachment = #"{\"name\":\"Hafez Application for iPhone\","
"\"href\":\"http://itunes.apple.com/us/app/divan-of-hafez/id340865571?mt=8?tab=iphone\","
"\"media\":[{\"type\":\"image\","
"\"src\":\"http://momeks.com/images/fb.png\","
"\"href\":\"http://developers.facebook.com/connect.php?tab=iphone/\"}],"
"\"properties\":{\"another link\":{\"text\":\"Hafez App HomePage\",\"href\":\"http://www.momeks.com/hafez\"}}}";
//replace this with a friends UID
//dialog2.targetId = #"999999";
[dialog2 show];
break;
case 2:
[session logout];
break;
}
}

The FBDialog's show method is asynchronous, meaning it returns before it completes whatever it is doing (in this case displaying a window).
You need to implement the delegate methods for responding to facebook dialog messages.
In the delegate methods you can outline the flow of your application.
Currently, your code show's the login dialog window, which returns instantly, and then proceeds on to show another dialog. You should only show the second dialog after the user has logged in, which you can determing using the FBSession delegate methods.

Related

Error! Twitter not Conecting from my IPhone

i m using AddThis SDK for facebook,twitter and Email share, facebook and Email is nicely working while Twitter is giving error while conecting from my Iphone. it nice work from my simulator but from iphone twitter not connecting and just display a message in console"Error!" code: [AddThisSDK setTwitterViaText:#"QuotesApp"];
[AddThisSDK shareURL:#"http://HazratAliQuotes.com"
withService:#"twitter" title:string description:#"QuotesApp"];
Try this link to implement Twitter in your application for previous version of iOS
The Previos API of twitter is known as MGTTwitter
For AddThis:
To use Twitter OAuth-enabled sharing, you'll need to tell the library to do so, and then configure your Twitter consumer key, consumer secret, and callback URL.
[AddThisSDK setTwitterAuthenticationMode:ATTwitterAuthenticationTypeOAuth];
[AddThisSDK setTwitterConsumerKey:#"yourconsumerkey"];
[AddThisSDK setTwitterConsumerSecret:#"yourconsumersecret"];
[AddThisSDK setTwitterCallBackURL:#"yourcallbackurl"];
Below is the new answer added.
Remove the line [AddThisSDK setTwitterViaText:#"QuotesApp"];
Add the line [AddThisSDK setTwitterAuthenticationMode:ATTwitterAuthenticationTypeOAuth];
and on twitter button pressed create a selector and add the following code as
[AddThisSDK shareURL:#"http://www.addthis.com"
withService:#"twitter"
title:#"AddThis - The #1 Bookmarking & Sharing Service"
description:#"AddThis is a free way to boost traffic back to your site by making it easier for visitors to share your content."];
This is optional answer for you. In IOS 5 there is framework Tweeter.Framework. add this Framework and import, i use this for uploading a image(as a link) and message. may be it's helpful for you.:)
import "Twitter/Twitter.h"
and on Button Click..
- (void)postImageOnTweeterWall
{
if (imageView.image)
{
NSLog(#"tweetbutton pressed called");
// Create the view controller
TWTweetComposeViewController *twitter = [[TWTweetComposeViewController alloc] init];
// Optional: set an image, url and initial text
[twitter addImage:[UIImage imageNamed:#"img1.jpeg"]];
// [twitter addURL:[NSURL URLWithString:[NSString stringWithString:#"http://MobileDeveloperTips.com/"]]];
[twitter setInitialText:#"Tweet from iOS 5 app using the Twitter framework."];
// Show the controller
[self presentModalViewController:twitter animated:YES];
// Called when the tweet dialog has been closed
twitter.completionHandler = ^(TWTweetComposeViewControllerResult result)
{
NSString *title = #"Tweet Status";
NSString *msg;
if (result == TWTweetComposeViewControllerResultCancelled)
msg = #"Tweet compostion was canceled.";
else if (result == TWTweetComposeViewControllerResultDone)
msg = #"Tweet composition completed.";
// Show alert to see how things went...
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:#"Okay" otherButtonTitles:nil];
[alertView show];
// Dismiss the controller
[self dismissModalViewControllerAnimated:YES];
};
}
else
{ UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:#"Tweeter" message:#"Select photo to Upload"
delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil] autorelease];
[alertView show];
}
}

Getting twitter account list in IOS-5 and user it with TWTweetComposeViewController

i am using Twitter with IOS - 5 integration. i used tweeting app provide by apple for this.I am using TWTweetComposeViewController for this.
But if i have more than 2 twitter accounts. it is getting my first account every time. but i want that list of my different account shown to me and then when i select one of account and then i can use it with TWTweetComposeViewController. i like to show like bellow image From :"username"
i have used this code :
- (IBAction)sendEasyTweet:(id)sender {
// Set up the built-in twitter composition view controller.
TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];
// Set the initial tweet text. See the framework for additional properties that can be set.
[tweetViewController setInitialText:#"Hello. This is a tweet."];
[tweetViewController addImage:[UIImage imageNamed:#"Icon.png"]];
// Create the completion handler block.
[tweetViewController setCompletionHandler:^(TWTweetComposeViewControllerResult result) {
NSString *output;
switch (result) {
case TWTweetComposeViewControllerResultCancelled:
// The cancel button was tapped.
output = #"Tweet cancelled.";
break;
case TWTweetComposeViewControllerResultDone:
// The tweet was sent.
output = #"Tweet done.";
break;
default:
break;
}
[self performSelectorOnMainThread:#selector(displayText:) withObject:output waitUntilDone:NO];
// Dismiss the tweet composition view controller.
[self dismissModalViewControllerAnimated:YES];
}];
// Present the tweet composition view controller modally.
[self presentModalViewController:tweetViewController animated:YES];
}
Unfortunately, TWTweetComposeViewController doesn't give you much configuration flexibility. If you tap on the account name it will pop up your list of accounts. TWTweetCVC does seem to remember the last account you tweeted with though.
If you use ACAccountStore you can get the list of the users Twitter accounts and you could provide your own UI to choose one but you cannot configure TWTweetComposeViewController to use it. If you couple that with TWRequest you can roll your own tweet sheet class and do this yourself.
DETweetComposeViewController is a drop-in replacement for TWTweetComposeViewController. It's open source, so you can modify it to meet your needs. It's also compatible with iOS 4.
Now , i am getting my it , and picker is showing for it as shown in image
so from this picker , i can select one of my account for tweet.

White blank screen after login in Facebook with FBConnect iphone

I am using FBConnect API...And I am using this code while pressing button..
- (IBAction)postGradesTapped:(id)sender {
_posting = YES;
// If we're not logged in, log in first...
if (![_session isConnected]) {
self.loginDialog = nil;
_loginDialog = [[FBLoginDialog alloc] init];
[_loginDialog show];
}
// If we have a session and a name, post to the wall!
else if (_facebookName != nil) {
[self postToWall];
}
// Otherwise, we don't have a name yet, just wait for that to come through.
}
Now when I press the button...
White blank screen Comes up...:(
What can be the problem??
As per your code, on login success you are posting on your wall. So it may be getting blank screen. Try print something on console on login success.

Limit providers while integrating Gigya in iPhone?

I am integrating Gigya in my iphone app. Now it provides 17 providers for access, I want to limit it to just 9 providers. How can I do that?
Has any one integrated it for iPhone? It loads a web view which displays 17 providers in a grouped table format, see here.
To set Facebook and Twitter you can use following code.
GSDictionary *pParams5 = [[GSDictionary new] autorelease];
[pParams5 putStringValue:#"facebook,twitter" forKey:#"enabledProviders"];
[gsAPI showAddConnectionsUI:pParams5 delegate:self context:nil];
GSAPI *gsAPI // declare this
gsAPI = [[GSAPI alloc] initWithAPIKey:<API-KEY> viewController:self]; // i kept this in viewDidload
// add this code to have facebook and twitter on provider list
GSDictionary *pParams5 = [[GSDictionary new] autorelease];
[pParams5 putStringValue:#"facebook,twitter" forKey:#"enabledProviders"];
[gsAPI showAddConnectionsUI:pParams5 delegate:self context:nil];
//this method called when login fails
-(void)gsLoginUIDidFail:(int)errorCode errorMessage:(NSString*)errorMessage context:(id)context{ }
// this method called on successful login
- (void) gsLoginUIDidLogin:(NSString*)provider user:(GSDictionary*)user context:(id)context {}
Check whether you have valid API

FBConnect won't display Publish to Wall after login

I have an app that I want to be able to connect to Facebook and post to the user's wall. I have the following code:
- (void)viewDidLoad {
static NSString* kApiKey = #"PRIVATE";
static NSString* kApiSecret = #"PRIVATE";
_session = [[FBSession sessionForApplication:kApiKey secret:kApiSecret delegate:self] retain];
// Load a previous session from disk if available. Note this will call session:didLogin if a valid session exists.
[_session resume];
// Set these values from your application page on http://www.facebook.com/developers
// Keep in mind that this method is not as secure as using the sessionForApplication:getSessionProxy:delegate method!
// These values are from a dummy facebook app I made called MyGrades - feel free to play around!
[super viewDidLoad];
}
- (IBAction)postGradesTapped:(id)sender {
_posting = YES;
// If we're not logged in, log in first...
if (![_session isConnected]) {
self.loginDialog = nil;
_loginDialog = [[FBLoginDialog alloc] init];
[_loginDialog show];
}
// If we have a session and a name, post to the wall!
else if (_facebookName != nil) {
[self postToWall];
}
// Otherwise, we don't have a name yet, just wait for that to come through.
}
The problem I have is that when the user clicks the button associated with the IBAction it will pop up the login dialog, but then the window disappears without ever pulling up the Publish Story to Wall dialog. How do I get it to login and then pull up the Publish Story to Wall?
I think you may need to use FBPermissionDialog to ask for "post to wall" permission first (I'm not sure what the exact string is; it might be in the examples).
Also note that "FBSession" is the old "iPhone" SDK (last updated in April); there's a newer "iOS" SDK at http://github.com/facebook/facebook-ios-sdk
I once encountered this behavior when my Security Key was wrong (in the new API you don't need it, but if you're based on old API it still requires it).
Make sure you use "App Id" and "App Secret" from the Facebook app control page. (And not "API Key")
Good luck!