【问题标题】:Post to twitter help - using php发布到 twitter 帮助 - 使用 php
【发布时间】:2011-01-01 19:09:57
【问题描述】:

我正在尝试向 twitter 发布一个 url,但该 url 是用户生成的并且是动态的......

<a href="http://twitter.com/?status=[urlencode('I'd like to borrow this item @neighborrow')].">TWEET THIS REQUEST</a> 

我从那个开始,但它没有捕捉到实际的网址——然后我尝试了其他一些,但它们似乎是用于静态网址

我必须使用 api 还是有办法让这个 urlencode 读取我们希望用户发布的特定 url?

谢谢

更新

<a href="http://twitter.com/?status=urlencode('I'd like to borrow this item @neighborrow')">TWEET THIS REQUEST</a> 
                <p><a href="http://twitter.com/home?status=I'd like to borrow this item @neighborrow http://http://neighborrow.com/wanted.php?item=22"> <img target="Borrow this from someone on twitter" src="PHOTOBUCKET direct URL HERE" alt="TWEET THIS (IMPROVE YOUR SELECTION)" title="" border="0" /></a></p>

基本上我想要两者的组合-如果您看到“item = 22”总是在变化-所以我想要一个按钮,代码将实际读取当前网址,而不仅仅是我在开头添加的静态网址.. . 这可能吗?

【问题讨论】:

    标签: php html api twitter character-encoding


    【解决方案1】:

    我认为一个问题可能是您使用“[ ]”方括号将字符串括起来,并以句点结束。

    除此之外,我可能会建议使用 htmlentities () 或 htmlspecialchars() 之类的东西。

    或者,您可能想考虑使用 API 来执行此操作。一方面,除非您在其他地方进行检查,否则无法保证用户已登录 twitter,并且 API 允许您使用 twitter 进行身份验证,而且 API 支持的时间可能比查询字符串请求更长。

    更新:
    我认为问题出在这部分代码中:

    <a href="http://twitter.com/?status=urlencode('I'd like to borrow this item @neighborrow')">TWEET THIS REQUEST</a>
    

    您调用了一个名为 urlencode 的函数,但它位于代码的 HTML 部分中,因此 PHP 不会执行该函数,HTML 只是将其解析为纯文本。 你想用这个替换它:

    <a href="http://twitter.com/?status=<?php echo (urlencode('I'd like to borrow this item @neighborrow')) ?>">TWEET THIS REQUEST</a>
    

    这应该让 php 代码解析它并返回编码的字符串。

    【讨论】:

    • 我不关心身份验证-如果他们没有帐户,他们不会发布-尽管我删除了括号仍然无法正常工作
    【解决方案2】:

    这里有一个非常方便的 PHP Twitter API 库:http://lab.arc90.com/2008/06/03/php-twitter-api-client/

    这将确保您不必解决已经解决的问题,您可以专注于编写代码。

    【讨论】:

      【解决方案3】:

      大概是这样的吧?

      <?php
       $posts = array (
            'i\'d like to borrow this item @neighborrow',
            'test this very carefully',
            'enough!!!'
           );
      
       foreach( $posts as $post )
       {
      ?>
      
        <a href="http://twitter.com/?status=<?php echo urlencode($post); ?>">tweet this request <small>[<?php echo $post; ?>]</small></a> <br/>
      <?php
       }
      ?>
      

      Liveview at codecookie.net

      希望我理解正确!

      【讨论】:

        猜你喜欢
        • 2013-03-14
        • 1970-01-01
        • 1970-01-01
        • 2011-09-20
        • 1970-01-01
        • 2011-07-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多