javascript - Any way to get widget-id for twitter widget from Twitter url? - Stack Overflow

Is there any way to find twitter widget id from twitter url?User will be putting there twitter urls and

Is there any way to find twitter widget id from twitter url?

User will be putting there twitter urls and I have to create widget for them like this

<a class="twitter-timeline" href="" data-widget-id="YOUR-WIDGET-ID-HERE">Tweets by @twitterapi</a>

<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>

But to generate this I need to have widget id! data-widget-id="YOUR-WIDGET-ID-HERE"

Is there any way to find twitter widget id from twitter url?

User will be putting there twitter urls and I have to create widget for them like this

<a class="twitter-timeline" href="https://twitter./twitterapi" data-widget-id="YOUR-WIDGET-ID-HERE">Tweets by @twitterapi</a>

<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter./widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>

But to generate this I need to have widget id! data-widget-id="YOUR-WIDGET-ID-HERE"

Share Improve this question edited Jun 17, 2013 at 11:41 Kees C. Bakker 33.5k31 gold badges118 silver badges207 bronze badges asked Jun 13, 2013 at 19:21 Pawan NogariyaPawan Nogariya 9,00813 gold badges59 silver badges131 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

Widgets can be created by logging into Twitter and:

  1. Go to: https://twitter./settings/widgets
  2. Press the 'Create new' button
  3. Fill in the settings
  4. Hit the 'Create widget' button

You widget ID will be visible in the code text box:

Indeed, there's no way to automatically find the widget id, but you can create a function in PHP to embed twitter on your website.

I created a simple plug-in for an open-source project:

---// twitter_plugin.php //-----

<?php    
function twitter_page ($search){

    # first we remove unwanted tags, for 
    # security reasons only and remove unwanted space.

    if($search ==""){
        exit;
    } else {
        //echo "<h2>" . $search . "</h2><br>";

        # wikipedia URL
        $url = "https://mobile.twitter./" . $search;

        # initialize curl
        $ch = curl_init();

        # Get the user agent of the visitor...

        $user_agent = "Mozilla/4.0 (patible; MSIE 6.0; Windows NT 5.1";
        $_referer ="http://www.google."; 

        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch,CURLOPT_USERAGENT,$user_agent);
        curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0);
        curl_setopt ($ch, CURLOPT_AUTOREFERER, 1);
        curl_setopt($ch,CURLOPT_REFERER,$_referer); 
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);



        $definition = curl_exec($ch);

        $cellphone = "You are on Twitter Mobile because you are using an old version of Internet Explorer. Learn more";
        $definition = str_replace($cellphone, "More information about Twitter ", $definition);
        $definition = str_replace('href="', ' target="_blank" href="', $definition);
        $definition = str_replace('action="', 'target="_blank" action="https://mobile.twitter./', $definition);
        $definition = str_replace("href='", " target='_blank' href='", $definition);
        $definition = str_replace('https://mobile.twitter./', 'https://twitter./', $definition);
        $definition = str_replace('href="/', 'href="https://twitter./', $definition);
        $definition = str_replace('class="tweet-text"', 'class="tweet-text" style="color:rgb(0,0,0);"', $definition);



        $needle = '<div class="w-mediaonebox">';
        $pos = strpos ($definition, $needle);
        $definition=substr($definition,$pos, strlen($definition));



        echo "<div class=\"w-mediaonebox\">\n" . $definition; 


        curl_close($ch);
        echo "</div>";

    } 
}



if(isset($twitter)){

    twitter_page($twitter); 

}

----// end of php script //----

And this is how you can use the plug-in:

<div style="height:880px; width:550px; overflow:auto; overflow-style:marquee-line;">
<?php
$twitter = 'nova_says';
include_once('include/twitter_plugin.php');
?>
</div>

A Demo of this plug-in can be found on: http://www.heathernova.us/index-page-405-category-405.html

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744637017a4585203.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信