将 Twitter 集成到 iPhone 应用程序
我希望将 Twitter 集成到我的应用程序中。我的项目是在 ARC
支持下创建的。当我添加 Twitter 框架时,我还使用 -fno-objc-arc
标记了 .m 文件。
我可以登录 Twitter(这意味着身份验证过程有效),身份验证后,当我单击推文按钮时,应用程序崩溃。
1.) 这是首先被调用的,twitter 身份验证工作正常。
-(void)loginTwitterUser{
if(_engine) return;
_engine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate:self];
_engine.consumerKey = @"xxxxxx";
_engine.consumerSecret = @"xxxxxx";
if (![_engine isAuthorized]) {
UIViewController *controller = [SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine:_engine delegate:self];
if (controller) {
[self presentModalViewController:controller animated:YES];
}
}
中合成它_engine
- 我已经声明这是.h
文件,但没有在.m
这是我们要发推文的地方
-(void)tweetThis:(id)sender{ [_engine sendUpdate:@"发推文"]; }
3.) 其他 delagate 方法
#pragma mark SA_OAuthTwitterEngineDelegate
- (void) storeCachedTwitterOAuthData: (NSString *) data forUsername: (NSString *) username {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject: data forKey: @"authData"];
[defaults synchronize];
}
- (NSString *) cachedTwitterOAuthDataForUsername: (NSString *) username {
return [[NSUserDefaults standardUserDefaults] objectForKey: @"authData"];
}
#pragma mark TwitterEngineDelegate
- (void) requestSucceeded: (NSString *) requestIdentifier {
NSLog(@"Request %@ succeeded", requestIdentifier);
}
- (void) requestFailed: (NSString *) requestIdentifier withError: (NSError *) error {
NSLog(@"Request %@ failed with error: %@", requestIdentifier, error);
}
#pragma mark SA_OAuthTwitterController Delegate
在 NSLog 中 username
是 null
。这是为什么?
- (void) OAuthTwitterController: (SA_OAuthTwitterController *) controller authenticatedWithUsername: (NSString *) username {
NSLog(@"Authenticated with user %@", username);
}
- (void) OAuthTwitterControllerFailed: (SA_OAuthTwitterController *) controller {
NSLog(@"Authentication Failure");
}
- (void) OAuthTwitterControllerCanceled: (SA_OAuthTwitterController *) controller {
NSLog(@"Authentication Canceled");
}
应用程序在 MGTwitterEngine.m
的 return 语句处崩溃。
- (NSString *)sendUpdate:(NSString *)status inReplyTo:(unsigned long)updateID
{
if (!status) {
return nil;
}
NSString *path = [NSString stringWithFormat:@"statuses/update.%@", API_FORMAT];
NSString *trimmedText = status;
if ([trimmedText length] > MAX_MESSAGE_LENGTH) {
trimmedText = [trimmedText substringToIndex:MAX_MESSAGE_LENGTH];
}
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
[params setObject:trimmedText forKey:@"status"];
if (updateID > 0) {
[params setObject:[NSString stringWithFormat:@"%u", updateID] forKey:@"in_reply_to_status_id"];
}
NSString *body = [self _queryStringWithBase:nil parameters:params prefixed:NO];
return [self _sendRequestWithMethod:HTTP_POST_METHOD path:path
queryParameters:params body:body
requestType:MGTwitterUpdateSendRequest
responseType:MGTwitterStatus];
}
我该如何解决这个问题?
I am hoping to integrate Twitter to my application. My project is created with ARC
support. When i added the Twitter framework i also flagged the .m files with -fno-objc-arc
.
I could login to twitter (meaning, the authentication process works), and after the authentication that application crashes when i click the tweet button.
1.) This is what gets called first, twitter authentication works fine.
-(void)loginTwitterUser{
if(_engine) return;
_engine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate:self];
_engine.consumerKey = @"xxxxxx";
_engine.consumerSecret = @"xxxxxx";
if (![_engine isAuthorized]) {
UIViewController *controller = [SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine:_engine delegate:self];
if (controller) {
[self presentModalViewController:controller animated:YES];
}
}
_engine
- i have declared this is the.h
file, but did not synthesize it in the.m
This is where we are going to tweet
-(void)tweetThis:(id)sender{ [_engine sendUpdate:@"Tweet something"]; }
3.) other delagate methods
#pragma mark SA_OAuthTwitterEngineDelegate
- (void) storeCachedTwitterOAuthData: (NSString *) data forUsername: (NSString *) username {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject: data forKey: @"authData"];
[defaults synchronize];
}
- (NSString *) cachedTwitterOAuthDataForUsername: (NSString *) username {
return [[NSUserDefaults standardUserDefaults] objectForKey: @"authData"];
}
#pragma mark TwitterEngineDelegate
- (void) requestSucceeded: (NSString *) requestIdentifier {
NSLog(@"Request %@ succeeded", requestIdentifier);
}
- (void) requestFailed: (NSString *) requestIdentifier withError: (NSError *) error {
NSLog(@"Request %@ failed with error: %@", requestIdentifier, error);
}
#pragma mark SA_OAuthTwitterController Delegate
In the NSLog username
is null
. Why is this ?
- (void) OAuthTwitterController: (SA_OAuthTwitterController *) controller authenticatedWithUsername: (NSString *) username {
NSLog(@"Authenticated with user %@", username);
}
- (void) OAuthTwitterControllerFailed: (SA_OAuthTwitterController *) controller {
NSLog(@"Authentication Failure");
}
- (void) OAuthTwitterControllerCanceled: (SA_OAuthTwitterController *) controller {
NSLog(@"Authentication Canceled");
}
The application crashes in the MGTwitterEngine.m
at the return statement.
- (NSString *)sendUpdate:(NSString *)status inReplyTo:(unsigned long)updateID
{
if (!status) {
return nil;
}
NSString *path = [NSString stringWithFormat:@"statuses/update.%@", API_FORMAT];
NSString *trimmedText = status;
if ([trimmedText length] > MAX_MESSAGE_LENGTH) {
trimmedText = [trimmedText substringToIndex:MAX_MESSAGE_LENGTH];
}
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
[params setObject:trimmedText forKey:@"status"];
if (updateID > 0) {
[params setObject:[NSString stringWithFormat:@"%u", updateID] forKey:@"in_reply_to_status_id"];
}
NSString *body = [self _queryStringWithBase:nil parameters:params prefixed:NO];
return [self _sendRequestWithMethod:HTTP_POST_METHOD path:path
queryParameters:params body:body
requestType:MGTwitterUpdateSendRequest
responseType:MGTwitterStatus];
}
How can i resolve this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
检查您的 SA_OAuthTwitterEngine.m 并尝试实施以下更改。您应该将 http 更改为 https。
Check your SA_OAuthTwitterEngine.m and try to implement the changes below. You should change http to https.
您没有理由这样做,Twitter 集成已经优化。
检查此链接 http://www.raywenderlich.com/5519/beginning- twitter-in-ios-5
There's no reason for you to do that, twitter integration has been optimized.
Check this link http://www.raywenderlich.com/5519/beginning-twitter-in-ios-5