Twitter网站意图缩短网址

时间:2015-04-03 16:19:55

标签: javascript twitter

我正在尝试使用Twitter Web Intents向我的页面添加自定义推文功能。这是一个包含大量查询参数的复杂页面,超过140个字符。网址不会缩短。

这是我正在使用的功能:

function tweet(image){
    var pageURL = createPreloadURL(image)
    var width  = 575,
        height = 400,
        left   = ($(window).width()  - width)  / 2,
        top    = ($(window).height() - height) / 2,
        url    = 'https://twitter.com/intent/tweet?url='+ encodeURIComponent(pageURL),
        opts   = 'status=1' +
         ',width='  + width  +
         ',height=' + height +
         ',top='    + top    +
         ',left='   + left;
        window.open(url, 'twitter', opts);
}

我安排了URL字符串,它似乎是正确的格式:

http%3A%2F%2Fexample.com%2Fpreload.cfm%3Fproduct_id%3D4420%26year%3D2014%26make_id%3D58%26model_id%3D21604%26diameter%3D17....

在文档here上,它说:

  

具有HTTP或HTTPS方案的完全限定URL,URL编码。该   提供的URL将缩短与Twitter的t.co到数量   short_url_length指定的字符。

     

示例值:http:%3A%2F%2Fexample.com%2F

我在新窗口中查看控制台我收到此错误

  

拒绝执行内联脚本,因为它违反了以下内容   内容安全策略指令:“script-src'unsafe-inline'   'nonce-PfLsh9SlUoh7UKtdZ7mgcA ==''unsafe-eval'https:“。注意   如果存在hash或nonce值,则忽略'unsafe-inline'   在源列表中。

我需要采取其他步骤才能使网址缩短工作吗?

1 个答案:

答案 0 :(得分:0)

我发现了我遇到的问题。我正在开发一个IP地址的开发链接。 Twitter的URL缩短显然不喜欢这样。当我在常规URL上测试它时,URL缩短了。

相关问题