关注我们iphone的twitter示例代码

时间:2012-10-18 05:55:52

标签: iphone sharekit

我正致力于推特整合部分,请关注我们 在Sharekit Follow方法不起作用对我有什么帮助 请你帮我解释一下在twitter上关注我们的示例代码

- (void)followMe
{
// remove it so in case of other failures this doesn't get hit again
[item setCustomValue:nil forKey:@"followMe"];

OAMutableURLRequest *oRequest = [[OAMutableURLRequest alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://api.twitter.com/1/friendships/create/%@.json", SHKTwitterUsername]]
                                                                consumer:consumer
                                                                   token:accessToken
                                                                   realm:nil
                                                       signatureProvider:nil];

NSLog(@"%@",SHKTwitterUsername);

[oRequest setHTTPMethod:@"POST"];

OAAsynchronousDataFetcher *fetcher = [OAAsynchronousDataFetcher asynchronousFetcherWithRequest:oRequest
                                                                                      delegate:nil // Currently not doing any error handling here.  If it fails, it's probably best not to bug the user to follow you again.
                                                                             didFinishSelector:nil
                                                                               didFailSelector:nil];    

[fetcher start];
[oRequest release];
}

2 个答案:

答案 0 :(得分:0)

使用非常简单:

[self.view addSubview:[[FollowMeButton alloc] initWithTwitterAccount:
@"chrismaddern" atOrigin:CGPointMake(205, 248) isSmallButton:YES]];

您只需在Interface Builder中更改UIButton的类,然后将其合成为属性。

或从....下载代码

https://github.com/chrismaddern/Follow-Me-On-Twitter-iOS-Button

答案 1 :(得分:0)

juz在您的.h @interface FollowMeButton : UIButton

中尝试此操作
@property (nonatomic) NSString* twitterAccount;
@property (nonatomic) BOOL isSmall;

-(id)initWithTwitterAccount:(NSString*)account atOrigin:(CGPoint)origin isSmallButton:(BOOL)isSmallButton; .M interface FollowMeButton()

@property (nonatomic) UIImageView *imageView;

-(void)buttonTapped;
@end

@implementation FollowMeButton

@synthesize imageView, twitterAccount, isSmall;

-(id)initWithTwitterAccount:(NSString*)account atOrigin:(CGPoint)origin isSmallButton:(BOOL)isSmallButton
{



CGSize buttonSize;



self.isSmall = isSmallButton;



if(isSmallButton)



buttonSize = CGSizeMake(61, 20);



else



buttonSize = CGSizeMake(122, 40);




self.twitterAccount = account;



CGRect buttonFrame = CGRectMake(origin.x, origin.y, buttonSize.width, buttonSize.height);



self = [super initWithFrame:buttonFrame];



if (self)



{



if(self.isSmall)



[self setBackgroundImage:[UIImage imageNamed:@"follow-me-small"] forState:UIControlStateNormal];



else



[self setBackgroundImage:[UIImage imageNamed:@"follow-me"] forState:UIControlStateNormal];




[self addTarget:self action:@selector(buttonTapped) forControlEvents:UIControlEventTouchUpInside];



}



return self;
}

-(void)buttonTapped
{



NSArray *urls = [NSArray arrayWithObjects:



@"twitter://user?screen_name={handle}", // Twitter



@"tweetbot:///user_profile/{handle}", // TweetBot



@"echofon:///user_timeline?{handle}", // Echofon



@"twit:///user?screen_name={handle}", // Twittelator Pro



@"x-seesmic://twitter_profile?twitter_screen_name={handle}", // Seesmic



@"x-birdfeed://user?screen_name={handle}", // Birdfeed



@"tweetings:///user?screen_name={handle}", // Tweetings



@"simplytweet:?link=http://twitter.com/{handle}", // SimplyTweet



@"icebird://user?screen_name={handle}", // IceBird



@"fluttr://user/{handle}", // Fluttr



@"http://twitter.com/{handle}",



nil];




UIApplication *application = [UIApplication sharedApplication];




for (NSString *candidate in urls) {



NSURL *url = [NSURL URLWithString:[candidate stringByReplacingOccurrencesOfString:@"{handle}" withString:twitterAccount]];



if ([application canOpenURL:url])



{



[application openURL:url];



return;



}



}

}

-(void)setIsSmall:(BOOL)shouldBeSmall
{



isSmall = shouldBeSmall;




CGSize buttonSize;



if(isSmall)



{



buttonSize = CGSizeMake(61, 20);



[self setBackgroundImage:[UIImage imageNamed:@"follow-me-small"] forState:UIControlStateNormal];



}



else



{



buttonSize = CGSizeMake(122, 40);



[self setBackgroundImage:[UIImage imageNamed:@"follow-me"] forState:UIControlStateNormal];



}




CGRect buttonFrame = CGRectMake(self.frame.origin.x, self.frame.origin.y, buttonSize.width, buttonSize.height);




[self setFrame:buttonFrame];
}

-(void)awakeFromNib
{



[super awakeFromNib];



if(self)



{



[self setFrame:CGRectMake(self.frame.origin.x, self.frame.origin.y, 122, 40)];



[self setBackgroundImage:[UIImage imageNamed:@"follow-me"] forState:UIControlStateNormal];



[self addTarget:self action:@selector(buttonTapped) forControlEvents:UIControlEventTouchUpInside];



}
}