问题描述
我想在高音应用程序中发推文,而不打算使用cordova。 我试过下面的插件: https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin
以下是如何使用插件发推的示例。问题是它在发布到高音扬声器之前向用户提供了一个弹出窗口(或确认框)。我希望它应该在没有用户意图的情况下发布。
window.plugins.socialsharing.shareViaTwitter('Message via Twitter')
感谢任何帮助!
解决方法
详细博客:http://sforsuresh.in/cordova-twitter-post-on-behalf-of-user
不知何故,我使用“codebird.js”库实现了
var cd = new Codebird;
var storage = window.localStorage;
cd.setToken(storage.getItem("oauth_token"),storage.getItem("oauth_token_secret"));
cd.__call("statuses_update",{ status: "This is my first tweet." },function(reply,rate,err) {
console.log("xxx"+JSON.stringify(reply));
});
上面的代码将在没有用户意图的情况下直接推文。 写上面的代码之前需要包含js:
<script src="js/codebird.js"></script>
为了获取用户令牌和密码,我使用了“cordova-twitter3-connect-plugin”插件,并且可以在“onDeviceReady()”上调用下面的函数来获取并存储在本地存储中。
function setusertoken() {
if(window.localStorage.getItem("oauth_token") != null) {
return false;
}
TwitterConnect.login(
function(result) {
var storage = window.localStorage;
storage.setItem("oauth_token",result.token);
storage.setItem("oauth_token_secret",result.secret);
},function(error) {
console.log('[Login] - Error logging in: ' + error);
}
);
}