How to get facebook, twitter profile(name ,image) in iOS6 - iphone

I have implemented facebook and twitter for ios6, but I'm not getting user details like name, email, image. Would help me anybody for this? Below is my code:
-(IBAction)facebook
{
SLComposeViewController *fbController=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result){
[fbController dismissViewControllerAnimated:YES completion:nil];
switch(result){
case SLComposeViewControllerResultCancelled:
default:
{
NSLog(#"Cancelled.....facebook");
}
break;
case SLComposeViewControllerResultDone:
{
NSLog(#"Posted....facebook");
}
break;
}};
[fbController addImage:[UIImage imageNamed:#"ipadicon_72x72.png"]];
[fbController setInitialText:#"Check out this article."];
//[fbController addURL:[NSURL URLWithString:#"http://soulwithmobiletechnology.blogspot.com/"]];
[fbController setCompletionHandler:completionHandler];
[self presentViewController:fbController animated:YES completion:nil];
}
}

See this info on using the Twitter framework and how to get information from Twitter, specifically, see Step 7.
http://mobile.tutsplus.com/tutorials/iphone/ios-sdk_twitter-framework_twrequest/

Related

Social framework - how to know if message was sent or not

I'm using Social framework in my project (iOS6), so user can make posts on Facebook or Twitter.
My question is, if there is a way to find out if user have sent a post to social network or he have canceled it and haven't published anything?
I use this code to share posts on Twitter:
-(IBAction)askOnTwitter
{
if (SYSTEM_VERSION_LESS_THAN(#"6.0"))
{
[self showErrorAlert];
twitterButton.enabled = NO;
return;
}
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
slComposeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[slComposeViewController setInitialText:#"Hey"];
[self presentViewController:slComposeViewController animated:YES completion:nil];
// So have user published a post or he haven't? How to know?
}
}
Does somebody know the trick? Thanks in advance.
You can set the completion handler for your compose view controller. There you will get the result SLComposeViewControllerResultDone or SLComposeViewControllerCancelled
__block __weak SLComposeViewController *slComposeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[slComposeViewController setCompletionHandler:^
(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultDone) {
NSLog(#"Done successfully");
}
else{
NSLog(#"Cancelled");
}
[slComposeViewController dismissViewControllerAnimated:YES completion:nil];
}];

shadow screen occur with Social Framework on iOS

I create application with feature 'shared with facebook'
I use this code for make a facebook sharing
[facebookViewController setInitialText:[NSString stringWithFormat:#"via %#", self.randomGame.name]];
NSLog(#"%#", self.resultImageView.image);
[facebookViewController addImage:self.resultImageView.image];
[facebookViewController setCompletionHandler:^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled) {
NSLog(#"Dialog Did Cancel");
}
}];
[self presentViewController:facebookViewController animated:YES completion:nil];
I already have allocation/initialization facebookViewController object with SLComposeViewController.
first time I share there is no problem.
But, I share second time I get a shadow screen like this
can anyone help ?
Thanks for advance.
i am not sure but every time you present the facebook popover you also need to dismiss it in the completion block like
[facebookViewController dismissViewControllerAnimated:YES completion:Nil];
hope it helps
I done it with code
facebookViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[facebookViewController setInitialText:[NSString stringWithFormat:#"via %#", self.randomGame.name]];
[facebookViewController addImage:self.resultImageView.image];
[self presentViewController:facebookViewController animated:YES completion:nil];

posting from iphone app to twitter and facebook

I am posting from my iphone app to both FB and twitter using the below code
But how can i post directly without showing a composer
-(IBAction)fbposting{
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook ]) {
slComplose = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[slComplose addImage:imageV.image];
[slComplose addURL:[NSURL URLWithString:#"http://newagesmb.com"]];
[slComplose setInitialText:self.textView.text];
[self presentViewController:slComplose animated:YES completion:nil];
}
[self.textView resignFirstResponder];
}
-(IBAction)twitposting{
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter ]) {
slComplose = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[slComplose setInitialText:self.textView.text];
[slComplose addURL:[NSURL URLWithString:#"http://newagesmb.com"]];
[slComplose addImage:imageV.image];
[self presentViewController:slComplose animated:YES completion:nil];
}
[self.textView resignFirstResponder];
}
Use following method in SLRequest class to get a Request object
+(SLRequest *)requestForServiceType:(NSString *)serviceType requestMethod:(SLRequestMethod)requestMethod URL:(NSURL *)url parameters:(NSDictionary *)parameters
then post the request
performRequestWithHandler

iOS - Posting to Facebook... is the icon this one?

I am posting to Facebook using the social api of iOS 6.
I am using the tradicional SLComposeViewController, like in..
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
...
at some point I do
[controller addImage:imageFacebook];
where imageFacebook is a screenshot that is 280 pixels high and then I post to Facebook.
My problem is this. I am following similar approach with the twitter API, but when that little window shows, there is a thumbnail of the image I am sending, hold by a clips on the right side, but on the facebook counterpart I see this safari-like icon. Is this normal? I would be a happy man if I was seen here a miniature of the image being posted, as I saw with the twitter API...
NOTE: the image is being posted correctly to Facebook... my problem is this icon on the posting window.
Is there a way to change that icon?
thanks
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled) {
NSLog(#"Cancelled");
} else {
NSLog(#"Done");
}
[controller dismissViewControllerAnimated:YES completion:Nil];
};
controller.completionHandler = myBlock;
[controller setInitialText:#"Enter Your Text Here:"];
[controller addURL:[NSURL URLWithString:#"http://www.google.com"]];
[controller addImage:[UIImage imageNamed:#"image001-794043.jpeg"]];
[self presentViewController:controller animated:YES completion:Nil];
} else {
NSLog(#"UnAvailable");
}

Twitter Post iOS6 'Cancel' button issue

I'm in the process of changing my app for iOS6 and iPhone use, I can't seem to figure out why when I post from Twitter using the new Social framework I have to press 'Cancel' twice to close, anybody else have this issue or a fix? Here is the code for the button.
- (IBAction)twitterPost:(id)sender
{
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
mySLComposerSheet = [[SLComposeViewController alloc] init];
mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[mySLComposerSheet setInitialText:[NSString stringWithFormat:#"This is my tweet, hello!",mySLComposerSheet.serviceType]];
[self presentViewController:mySLComposerSheet animated:YES completion:nil];
}
[mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
NSLog(#"dfsdf");
switch (result) {
case SLComposeViewControllerResultCancelled:
break;
case SLComposeViewControllerResultDone:
break;
default:
break;
}
}];
}
If your using the mySLComposerSheet this works great...
[mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
[mySLComposerSheet dismissViewControllerAnimated:YES completion:nil];
My experience with SLComposeViewController is that twitter and weibo controllers need to be dismissed manually while the facebook controller seems to be better behaved.
If I don't dismissViewControllerAnimated myself, tapping the "Send" button will send the tweet or weibo posting but I'll be left with what seems to be an invisible view over my own view. Thus I can no longer interact with my app.
I don't know why my app is working like this... Interestingly, the completionHandler for cancel gets called just once. The second tap dismisses the view controller.
+ (void) shareText:(NSString*)text image:(UIImage*)image social:(NSString*)service url:(NSString*)url
{
SLComposeViewController* controller = [SLComposeViewController composeViewControllerForServiceType:service];
[controller setInitialText:text];
[controller addImage:image];
[controller addURL:[NSURL URLWithString:url]];
controller.completionHandler = ^(SLComposeViewControllerResult result) {
if( SLComposeViewControllerResultDone == result )
{
NSLog(#"rewards for share: %#!", service );
}
if( ![SLServiceTypeFacebook isEqualToString:service] ) // facebook behaves
[[CBLAppDelegate instance].activeViewController dismissViewControllerAnimated:true completion:nil];
};
[[CBLAppDelegate instance].activeViewController presentViewController:controller animated:true completion:nil];
}
Found the issue. It only happens when a completion handler is added to TWTweetComposeViewController. If added, make sure to call:
[self dismissModalViewControllerAnimated:YES];
Try this buddy
[mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
switch (result) {
case SLComposeViewControllerResultCancelled:
[self performSelector:#selector(showalert)];
[mySLComposerSheet dismissViewControllerAnimated:YES completion:nil];
break;
case SLComposeViewControllerResultDone:
[self performSelector:#selector(showalert1)];
[mySLComposerSheet dismissViewControllerAnimated:YES completion:nil];
break;
default:
break;
}
}];
Posting comment above as an answer:
Have you tried setting the completionHandler before presenting the View Controller?