Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何利用write-api实现批量发帖 #1

Open
riddle911 opened this issue Jan 12, 2017 · 2 comments
Open

如何利用write-api实现批量发帖 #1

riddle911 opened this issue Jan 12, 2017 · 2 comments

Comments

@riddle911
Copy link
Contributor

关键字:批量发帖,excel,vba

出于某种目的,需要将excel中的数据批量生成帖子,使用write-api,这里介绍思路,可以用多种语言实现。
利用excel vba实现,其中A列代表时间,


Dim XMLHTTP As New MSXML2.XMLHTTP, myurl, turl As String
Dim i, j, data, ccid, ccontent, ctitle As String
Dim cdata

myurl = "http://host/api/v1/topics/"
turl = myurl & "8" **8是category的ID
'data = "username=中d文&password=pass123&email=z88@q.com"

ccid = "cid=1"
ctitle = "&title=" & [e1]  **e1单元格为topic名称
ccontent = "&content=" & [e1]  **topic内容也使用e1单元格

data = ccid + ctitle + ccontent
MsgBox data

XMLHTTP.Open "POST", myurl, False
XMLHTTP.setRequestHeader "Authorization", "Bearer xxxxx"
XMLHTTP.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
XMLHTTP.Send data
Debug.Print (XMLHTTP.responseText)


For i = 2 To 10


cdata = "content=" & Cells(i, 5)   **(i,5)代表从E2-E10单元格取发帖内容,即post

XMLHTTP.Open "POST", turl, False
XMLHTTP.setRequestHeader "Authorization", "Bearer xxxxx"
XMLHTTP.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
XMLHTTP.Send cdata
Debug.Print (XMLHTTP.responseText)
Next
'MsgBox (XMLHTTP.responseText)

End Sub```
@xuelainiao
Copy link

是否可以贴出来一个example excel,我不是很明白e1为何即存储title又存储content

@riddle911
Copy link
Contributor Author

@xuelainiao
这个没啥特殊的,就是把帖子的内容和标题都用了一个字段传了。。我是懒的再放个单元格专门放content了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants