如何使用nodejs代码在新浪微博上发布帖子
生活随笔
收集整理的這篇文章主要介紹了
如何使用nodejs代码在新浪微博上发布帖子
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
我寫了一小段程序,代碼如下:
var config = require("./mcConfig.js"); var request = require("request");function sendWCMeaasge(content, callback){var postData = {location:"v6_content_home",text: content,style_type:"1",isReEdit:false,module:"stissue",pub_source:"main_",pub_type:"dialog",isPri:0,_t:0};var options = {url: "https://www.weibo.com/aj/mblog/add?ajwvr=6&__rnd=1564468131832",method: "POST",headers: {"cookie": config.cookie,"origin": "https://www.weibo.com","referer": "https://www.weibo.com/abap/home?wvr=5","content-type": "application/x-www-form-urlencoded"},form: postData};request(options,function(error,response,data){// console.log(data);if( !!data){var oResponse = JSON.parse(data);callback(oResponse.code);}});}module.exports = sendWCMeaasge;使用下面這段簡單的代碼來消費這個發送函數:
var tool = require("./SendWeiboModule.js"); var config = require("./mcConfig.js");tool("i042416", function(code){console.log("response from Weibo: " + code); });使用命令行執行這個nodejs應用:
發送一條微博,內容為i042416: 馬上在瀏覽器上就能看到這條帖子了:要獲取更多Jerry的原創文章,請關注公眾號"汪子熙":
總結
以上是生活随笔為你收集整理的如何使用nodejs代码在新浪微博上发布帖子的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ubuntu如何卸载docker
- 下一篇: 数据结构–(ElemType