1

私はTwitterの統合部分に取り組んでいますfr私たちをフォローしてください
Sharekitでフォローメソッドが機能していませんこれで私を助けてくれますか?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];
}
4

2 に答える 2

0

あなたの.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];



}
}
于 2012-10-18T09:02:09.330 に答える
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

于 2012-10-18T07:11:04.097 に答える