0

ソーシャル メディアの Web サイト、特に Twitter で簡単に共有できる、ランダムに生成されたフレーズを作成しようとしています。次の PHP コードを使用して、ランダムなフレーズを生成しています。

このコードは、'responses.txt' でフレーズを含む行を検索し、その行を呼び出すことができます。

<!-- HEADER -->
<?php
$randomThings = file('**responses.txt**', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
?>

<!-- CALL SCRIPT -->
<?php
echo $randomThings[mt_rand(0,count($randomThings)-1)];
?>

たとえば、この生成された行の横に、(#[websitename] を介して) 所定の #hatchtag を付けてフレーズをリツイートするリツイート ボタンを配置するにはどうすればよいでしょうか。

私はツイッターの側面にもっと興味がありますが、他のソーシャルメディアのウェブサイトが他の人を助けることができます.

4

1 に答える 1

0

The re-tweet intent itself has problems right now. It's been filed as a bug since November so I don't think you'll want to use the re-tweet functionality from an external website. You can simulate a re-tweet with a regular tweet intent and pre-filling in the text, (which sounds like what you actually want to do). With the tweet intent you send a HTTP request to https://twitter.com/intent/tweet. You could then include the text parameter to pre-fill the text when the HTTP request is sent, or the link is clicked.

Using your example it would look something like this:

<!-- HEADER -->
    <?php
    $randomThings = file('**responses.txt**', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
    ?>

    <!-- CALL SCRIPT -->
    <?php
    $newThings = $randomThings[mt_rand(0,count($randomThings)-1)]; //must evaluate to a string
    echo $newThings;
    echo '<a href="https://twitter.com/intent/tweet?text='.$newThings.'">Link text</a>';
    ?>

this would be an unstyled link instead of a "button" but you can adapt it to be a button using standard HTML/CSS styling.


ref: https://dev.twitter.com/docs/intents

于 2011-12-22T05:21:13.503 に答える