我想確認用戶在點擊Twitter Web Intent後發微博。我怎樣才能做到這一點?如何確認Twitter網頁意圖已發送?
例子:
<a href="https://twitter.com/intent/tweet?text=Simple+Web+Intent">Tweet</a>
假設匿名*用戶點擊此鏈接,微博,我怎麼能證實這一點?
理想情況下,我很想獲取tweet的鏈接。
* anonymous
在未通過身份驗證在我的網站和不知道他們的Twitter用戶名
我想確認用戶在點擊Twitter Web Intent後發微博。我怎樣才能做到這一點?如何確認Twitter網頁意圖已發送?
例子:
<a href="https://twitter.com/intent/tweet?text=Simple+Web+Intent">Tweet</a>
假設匿名*用戶點擊此鏈接,微博,我怎麼能證實這一點?
理想情況下,我很想獲取tweet的鏈接。
* anonymous
在未通過身份驗證在我的網站和不知道他們的Twitter用戶名
更新
這種解決方案不再適用的Twitter更新小工具的行爲之後。您只能跟蹤是否現在點擊了推文按鈕,而不會推送實際發佈的推文。
可以追蹤使用 'twttr.events.bind' 事件偵聽器形成Twitter的API鳴叫。跟蹤鳴叫的工作示例可以在這裏找到:http://jsfiddle.net/EZ4wu/3/
HTML:
<a href="https://twitter.com/intent/tweet?url=https://www.webniraj.com/2012/09/11/twitter-api-tweet-button-callbacks/&text=Twitter+API:+Tweet+Button+Callbacks"><i class="icon-twitter-sign icon-white"></i> Tweet</a>
的JavaScript:
function reward_user(event) {
if (event) {
alert('Tweeted');
console.log(event);
}
}
window.twttr = (function (d,s,id) {
var t, js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return; js=d.createElement(s); js.id=id;
js.src="//platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs);
return window.twttr || (t = { _e: [], ready: function(f){ t._e.push(f) } });
}(document, "script", "twitter-wjs"));
twttr.ready(function (twttr) {
twttr.events.bind('tweet', reward_user);
});
我previous solution現在已經過時,不再似乎工作。
試試這個:
twttr.events.bind('loaded', function(event) {
window.location = "http://theredirect_link.com"
});
@ Niroj的回答不再起作用。他們更新了api,所以事件監聽器在用戶點擊按鈕後立即觸發 - 你無法檢查他是否實際發送了推文。
如果您自己創建窗口(不使用Twitter窗口小部件),則至少可以檢測到窗口是否關閉(用戶關閉它或發送微博)。
不要鏈接小部件api!
HTML:
<a id="twitter-intent" href="https://twitter.com/intent/tweet?url=https://www.webniraj.com/2012/09/11/twitter-api-tweet-button-callbacks/&text=Twitter+API:+Tweet+Button+Callbacks"><i class="icon-twitter-sign icon-white"></i> Tweet</a>
JS:
document.getElementById('twitter-intent').addEventListener('click', function(e) {
e.preventDefault();
e.stopPropagation(); //this should do in case you don't want to unlink twitter widgets api
var width = 575,
height = 400,
left = (screen.width - width)/2,
top = (screen.height - height)/2,
url = this.href,
opts = 'status=1' +
',width=' + width +
',height=' + height +
',top=' + top +
',left=' + left;
var win = window.open(url, 'twitter_share', opts);
var timer = setInterval(checkWin, 500);
function checkWin() {
if (win.closed) {
//just assume the user tweeted (he could just close the window without tweeting)
alert("Thank you for tweeting!");
clearInterval(timer);
}
}
});
@尼拉吉 - 沙阿,你能在https://www.webniraj.com/2012/09/得到您的解決方案的工作的jsfiddle 11/twitter-api-tweet-button-callbacks /?我無法讓它迴歸。它不再起作用了嗎? – Ryan
看起來不再有效,但我有一個解決方案給你! –