菜鸟教程小白 发表于 2022-12-13 15:08:31

iphone - Twitter API(从 ID 到屏幕名称)


                                            <p><p>我正在尝试将 Twitter 用户 ID(例如:77687121)转换为他们的用户名或屏幕名称(任何一个都可以),但我遇到了问题...</p>

<p>我尝试按照这个 SO 问题的指示,但是对于 Twitter api 以及 Objective c 本身来说都是新手,这让我很难理解:<em>http://stackoverflow.com/questions/10020672/php- twitter-api-get-users-lookup-grabbing-screen-name-from-id</em> </p>

<p>我从该教程中编写了以下代码,我得到了这个......</p>

<pre><code>- (void) turnFriendId: (NSString *)friID {
// Setup the URL, as you can see it&#39;s just Twitter&#39;s own API url scheme. In this case we want to receive it in JSON
NSLog(@&#34;%@&#34;,friID);
NSURL *followingURL = ;
// Pass in the parameters (basically &#39;.ids.json?screen_name=&#39;)
NSDictionary *parameters = ;
// Setup the request
TWRequest *twitterRequest = [ initWithURL:followingURL
                                                parameters:parameters
                                             requestMethod:TWRequestMethodGET];
// This is important! Set the account for the request so we can do an authenticated request. Without this you cannot get the followers for private accounts and Twitter may also return an error if you&#39;re doing too many requests
;
// Perform the request for Twitter friends
[twitterRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
    if (error) {
      // deal with any errors - keep in mind, though you may receive a valid response that contains an error, so you may want to look at the response and ensure no &#39;error:&#39; key is present in the dictionary
    }
    NSError *jsonError = nil;
    // Convert the response into a dictionary
    NSDictionary *twitterGrabbedUserInfo = ;
    // Grab the Ids that Twitter returned and add them to the dictionary we created earlier
    NSLog(@&#34;%@&#34;, );
}];
}
</code></pre>

<p>这种方法有时会给我一个错误,有时它会中断并显示一些汇编代码...下面是错误... <strong>以及第一个 NSLOG();在方法的开头...</strong></p>

<pre><code>2012-07-23 18:42:05.786 VideoPush 1882208
2012-07-23 18:42:17.692 VideoPush -: unrecognized selector sent to instance 0x1afeb0
2012-07-23 18:42:17.694 VideoPush -: unrecognized selector sent to instance 0x1afeb0
2012-07-23 18:42:17.696 VideoPush *** Terminating app due to uncaught exception &#39;NSInvalidArgumentException&#39;, reason: &#39;-: unrecognized selector sent to instance 0x1afeb0&#39;
*** First throw call stack:
(0x355e188f 0x37988259 0x355e4a9b 0x355e3915 0x3553e650 0x3055bfc3 0x3055b98b 0x35065d2f 0x355c1975 0x3553c1df 0x3554fb5f 0x35080b8b 0x35080b2b 0x3257dfdf 0x3257e88d 0x3257ea6b 0x3257eea5 0x355e3a83 0x3553e650 0x3055cf85 0x322047b1 0x32204e5d 0x31f1f 0x31d8d 0x32204f8b 0x3446ec59 0x34470d0f 0x34470b75 0x344717e7 0x3299edfb 0x3299ecd0)
terminate called throwing an exception(lldb)
</code></pre>

<p><strong>这也是一个很好的方法来遍历每个单独的 Twitter id(即使我有数千个)只是为了获取每个用户的屏幕名称。我知道 Twitter 有 API 限制...</strong></p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>运行 <code>users/lookup</code> 调用</p>

<pre><code>http://api.twitter.com/1/users/lookup.json?user_id=77687121,43662011,6253282
</code></pre>

<p>您可以用逗号分隔 I.D 以调用一个电话。</p>

<p>响应示例请看这里:</p>

<p> <a href="https://snap.apigee.com/NHcXs4" rel="noreferrer noopener nofollow">https://snap.apigee.com/NHcXs4</a> </p></p>
                                   
                                                <p style="font-size: 20px;">关于iphone - Twitter API(从 ID 到屏幕名称),我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/11621677/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/11621677/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iphone - Twitter API(从 ID 到屏幕名称)