简体   繁体   English

有什么方法可以从Twitter网址获取Twitter小部件的小部件ID?

[英]Any way to get widget-id for twitter widget from Twitter url?

Is there any way to find twitter widget id from twitter url? 有什么办法可以从Twitter网址中找到Twitter小部件ID?

User will be putting there twitter urls and I have to create widget for them like this 用户将在其中放置Twitter网址,我必须像这样为他们创建小部件

<a class="twitter-timeline" href="https://twitter.com/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.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>

But to generate this I need to have widget id! 但是要生成此文件,我需要具有小部件ID! data-widget-id="YOUR-WIDGET-ID-HERE"

Widgets can be created by logging into Twitter and: 可以通过登录Twitter和以下方式创建小部件:

  1. Go to: https://twitter.com/settings/widgets 前往: https//twitter.com/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: 您的小部件ID将在代码文本框中显示:

截屏

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. 确实,无法自动找到小部件ID,但是您可以使用PHP创建函数以将twitter嵌入到您的网站上。

I created a simple plug-in for an open-source project: 我为一个开源项目创建了一个简单的插件:

---// twitter_plugin.php //----- --- // 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.com/" . $search;

        # initialize curl
        $ch = curl_init();

        # Get the user agent of the visitor...

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

        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.com/', $definition);
        $definition = str_replace("href='", " target='_blank' href='", $definition);
        $definition = str_replace('https://mobile.twitter.com/', 'https://twitter.com/', $definition);
        $definition = str_replace('href="/', 'href="https://twitter.com/', $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 //---- ---- // php脚本的结尾// ----

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 可以在以下位置找到该插件的演示: http : //www.heathernova.us/index-page-405-category-405.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM