如何在 Angular 6 应用程序中嵌入 Twitter 时间线

Fel*_*Fel 3 angular

我想将 Twitter 时间线嵌入到 Angular 6 应用程序中,但找不到好的解决方案。这是我尝试过的:

  • 将 Twitter 生成的代码从“publish.twitter.com”放入 index.html。
  • 安装ngx-twitter-timeline包。我收到这个警告是因为我使用的是 Angular 6 和 RxJS 6,所以我卸载了它:

在此处输入图片说明

  • 安装ng4-twitter-timeline包。它似乎有严重的漏洞:

在此处输入图片说明

我怎么能得到它?提前致谢,

Cur*_*rse 9

您不需要安装任何软件包:

索引.html

<head>
   <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
</head>
Run Code Online (Sandbox Code Playgroud)

app.component.html :

<a class="twitter-timeline" href="https://twitter.com/TwitterDev?ref_src=twsrc%5Etfw">
   Tweets by TwitterDev
</a>
Run Code Online (Sandbox Code Playgroud)

app.component.ts :

ngAfterViewInit(): void {
    (<any>window).twttr.widgets.load();
}
Run Code Online (Sandbox Code Playgroud)

来源:https : //developer.twitter.com/en/docs/twitter-for-websites/timelines/overview.html


Fel*_*Fel 0

正如我所读到的,由于 CORS 安全机制,没有仅使用 Angular 的方式来获取 Twitter 时间线。不过,我发现了一些使用 NodeJS 完成此操作的好教程,例如:

http://thelillysblog.com/2017/02/26/getting-twitter-feed-angular-nodejs/