如何从 Objective-C 代码获取 Twitter 用户名?
我使用 Twitter-OAuth-iPhone 来授权和发送推文,并希望显示对话框视图上用户的 Twitter 用户名。虽然代码可以正确获取用户名,但始终会出现警告:
*'SA_OAuthTwitterEngine' 可能不会响应 '-extractUsernameFromHTTPBody:' (没有匹配方法签名的消息将被假定返回 'id' 并接受 '... ' 作为参数。)*
我用来获取 Twitter 用户名的代码是:
_engine=[[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate:self];
...
NSString *cachedData=[[NSUserDefaults standardUserDefaults] objectForKey:@"authData"];
NSString *twitterName=[_engine extractUsernameFromHTTPBody:cachedData];
NSLog(@"username: %@", twitterName);
SA_OAuthTwitterEngine.m 中的 extractUsernameFromHTTPBody 的格式是: - (NSString *) extractUsernameFromHTTPBody:(NSString *)body;
为什么警告?获取 Twitter 用户名的正确方法是什么?
I use the Twitter-OAuth-iPhone to authorise and send tweets, and want to show the user's twitter username on the dialog view. Although the code can get the username right, but there is always a warning:
*'SA_OAuthTwitterEngine' may not respond to '-extractUsernameFromHTTPBody:' (Messages without a matching method signature will be assumed to return 'id' and accept '...' as arguments.)*
The code I use to get the Twitter username are:
_engine=[[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate:self];
...
NSString *cachedData=[[NSUserDefaults standardUserDefaults] objectForKey:@"authData"];
NSString *twitterName=[_engine extractUsernameFromHTTPBody:cachedData];
NSLog(@"username: %@", twitterName);
The format of extractUsernameFromHTTPBody in the SA_OAuthTwitterEngine.m is: - (NSString *) extractUsernameFromHTTPBody:(NSString *)body;
Why the warning? What is the right way for getting the Twitter username?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否在自己的代码中包含
SA_OAuthTwitterEngine
的头文件?这就是告诉编译器该类定义了哪些方法。编辑
好的,根据您对我的回答的评论,我查看了源代码。您正在使用的方法被记录为私有方法,因此未在头文件中声明。这导致了警告。
我认为您应该使用
MGTwitterEngine.h
中定义的checkUserCredentials
方法来获取有关登录用户的详细信息,例如用户名。Are you including the header file for
SA_OAuthTwitterEngine
in your own code? That's what tells the compiler which methods the class has defined.Edit
Okay, following your comment on my answer, I've looked at the source code. The method you're using is documented as private, and as such is not declared in the header file. This is causing the warning.
I think you should be using the method
checkUserCredentials
as defined inMGTwitterEngine.h
to obtain details about the logged in user such as the username.