菜鸟教程小白 发表于 2022-12-13 00:22:31

ios - 在没有 TWTweetComposeViewController 的情况下发送推文


                                            <p><p>我想直接从我的 iPhone 应用发送推文而不显示 <code>TWTweetComposeViewController</code> 弹出窗口</p>

<p>我也想获得所有关注者
有没有办法从 ios5 上的 twitter 框架中做到这一点,或者我应该使用另一个 api!</p>

<p>如果我必须使用另一个 api,你可以为我指定一个很棒的 api 吗?因为我找到的所有 api
互联网上的东西太老了。</p>

<p>提前致谢</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>如果您使用的是 iOS 5.0 及更高版本,您可以使用 <code>TWRequest</code> 以编程方式从我的应用发布推文。发布推文非常简单,不需要外部框架或任何东西。</p>

<p>您需要 <code>#import <Twitter/Twitter.h></code>。您从 iPhone 帐户商店检索 twitter 帐户(您可以检查是否有多个帐户),然后使用该帐户发布请求。 </p>

<p>这里是使用图片发布推文的方法示例。</p>

<pre><code>- (void)shareTwitterImage:(UIImage *)image
{
    ACAccountStore *accountStore = [ init];
    ACAccountType *accountType = ;

    [accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error)
   {
         if(granted)
         {
             NSArray *accountsArray = ;

             if ( &gt; 0)
             {
               ACAccount *twitterAccount = ;

               TWRequest *postRequest = [ initWithURL: parameters: requestMethod:TWRequestMethodPOST];

               ;
               ;

               [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
                  {
                      //show status after done
                      NSString *output = ];
                      NSLog(@&#34;Twiter post status : %@&#34;, output);
                  }];
             }
         }
   }];
}
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 在没有 TWTweetComposeViewController 的情况下发送推文,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/14192003/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/14192003/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 在没有 TWTweetComposeViewController 的情况下发送推文