api - ASP: Upload Image to Twitter -


this code work ok

m_struseragent="user agent" m_strhost="api.twitter.com" m_metodo="post"  url_publish = "https://api.twitter.com/1.1/statuses/update.json" url_publish_img = "https://upload.twitter.com/1.1/media/upload.json"   oauth_consumer_key = "xxxxxxxxxxxxxxxxxxxxx" oauth_consumer_sec = "xxxxxxxxxxxxxxxxxxxxx" oauth_token = "xxxxxxxxxxxxxxxxxxxxx" oauth_token_sec = "xxxxxxxxxxxxxxxxxxxxx"  post_text="sample text"  oauth_nonce = year(now) & month(now) & day(now) & hour(now) & minute(now) & second(now) & replace(request.servervariables("remote_addr"),".","") oauth_signature_method = "hmac-sha1" oauth_timestamp = datediff("s", "01/01/1970 00:00:00", now()) oauth_version = "1.0"    oauth_sign = "oauth_consumer_key=" & oauth_consumer_key & "&oauth_nonce=" & oauth_nonce & "&oauth_signature_method=" & oauth_signature_method & "&oauth_timestamp=" & oauth_timestamp & "&oauth_token=" & oauth_token &  "&oauth_version=" & oauth_version & "&status=" & encodestring(post_text) oauth_signature = b64_hmac_sha1(oauth_consumer_sec&"&"&oauth_token_sec, m_metodo & "&" & encodestring(url_publish) & "&" & encodestring(oauth_sign)) param_auth="oauth_consumer_key=" & oauth_consumer_key & "&oauth_nonce=" & oauth_nonce & "&oauth_signature=" & encodestring(oauth_signature) & "&oauth_signature_method=hmac-sha1&oauth_timestamp=" & oauth_timestamp & "&oauth_token=" & oauth_token & "&oauth_version="&oauth_version  requesturl=url_publish & "?" & param_auth & "&status=" & server.urlencode(post_text),space(1),"+")  set objsrvhttp = server.createobject("msxml2.serverxmlhttp") objsrvhttp.settimeouts 10000, 10000, 15000, 15000 objsrvhttp.open m_metodo, requesturl, false objsrvhttp.setoption(2)=13056 objsrvhttp.setrequestheader "content-type","application/x-www-form-urlencoded" objsrvhttp.setrequestheader "user-agent", m_struseragent objsrvhttp.setrequestheader "host", m_strhost objsrvhttp.send   response.write objsrvhttp.status & " - " & objsrvhttp.statustext & "<br />" response.write objsrvhttp.responsetext 

but want post text , image , not work.

m_struseragent="user agent" m_strhost="api.twitter.com" m_metodo="post"  url_publish = "https://api.twitter.com/1.1/statuses/update.json" url_publish_img = "https://upload.twitter.com/1.1/media/upload.json"   oauth_consumer_key = "xxxxxxxxxxxxxxxxxxxxx" oauth_consumer_sec = "xxxxxxxxxxxxxxxxxxxxx" oauth_token = "xxxxxxxxxxxxxxxxxxxxx" oauth_token_sec = "xxxxxxxxxxxxxxxxxxxxx"  post_text="sample text"  oauth_nonce = year(now) & month(now) & day(now) & hour(now) & minute(now) & second(now) & replace(request.servervariables("remote_addr"),".","") oauth_signature_method = "hmac-sha1" oauth_timestamp = datediff("s", "01/01/1970 00:00:00", now()) oauth_version = "1.0"  localfile="c:\tmp\_tw668995883.jpg" base=convertimagetobase64(localfile) base64="data:image/jpeg;base64," & base  oauth_sign = "oauth_consumer_key=" & oauth_consumer_key & "&oauth_nonce=" & oauth_nonce & "&oauth_signature_method=" & oauth_signature_method & "&oauth_timestamp=" & oauth_timestamp & "&oauth_token=" & oauth_token &  "&oauth_version=" & oauth_version oauth_signature = b64_hmac_sha1(oauth_consumer_sec&"&"&oauth_token_sec, m_metodo & "&" & encodestring(url_publish_img) & "&" & encodestring(oauth_sign)) param_auth="oauth_consumer_key=" & oauth_consumer_key & "&oauth_nonce=" & oauth_nonce & "&oauth_signature=" & encodestring(oauth_signature) & "&oauth_signature_method=hmac-sha1&oauth_timestamp=" & oauth_timestamp & "&oauth_token=" & oauth_token & "&oauth_version="&oauth_version  requesturl=url_publish_img & "?" & param_auth   set objsrvhttp = server.createobject("msxml2.serverxmlhttp") objsrvhttp.settimeouts 10000, 10000, 15000, 15000 objsrvhttp.open m_metodo, requesturl, false objsrvhttp.setoption(2)=13056 objsrvhttp.setrequestheader "content-type","application/x-www-form-urlencoded" objsrvhttp.setrequestheader "user-agent", m_struseragent objsrvhttp.setrequestheader "host", m_strhost objsrvhttp.send   response.write objsrvhttp.status & " - " & objsrvhttp.statustext & "<br />" response.write objsrvhttp.responsetext  public function convertimagetobase64(filepath)   dim inputstream   set inputstream = createobject("adodb.stream")   inputstream.open   inputstream.type = 1  ' adtypebinary   inputstream.loadfromfile filepath   dim bytes: bytes = inputstream.read   dim dom: set dom = createobject("microsoft.xmldom")   dim elem: set elem = dom.createelement("tmp")   elem.datatype = "bin.base64"   elem.nodetypedvalue = bytes   convertimagetobase64 = replace(elem.text, vblf, "") end function 

what , do? twitter said always:

401 - authorization required {"errors":[{"code":32,"message":"could not authenticate you."}]}

any suggestion?

create boundary :

boundarystr = "---------------------------7d92a4b1705ba"  boundary = "-----------------------------7d92a4b1705ba"  requestbody = boundary & vbcrlf  requestbody = requestbody & "content-disposition: form-data; name=""media""; filename=""_tw668995883.jpg""" & vbcrlf  requestbody = requestbody & "content-type: application/octet-stream" & vbcrlf & vbcrlf requestbody = requestbody & escape(readbinaryfile(localfile)) & vbcrlf & boundary & "--" & vbcrlf  

add post

objsrvhttp.setrequestheader "accept", "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, application/octet-stream, */*" objsrvhttp.setrequestheader "content-length", len(requestbody) objsrvhttp.setrequestheader "content-type", "multipart/form-data; boundary=" & boundarystr objsrvhttp.send requestbody   function readbinaryfile(fullfilepath)      dim stream     set stream = server.createobject("adodb.stream")         stream.type = 1         stream.open()         stream.loadfromfile(fullfilepath)         readbinaryfile = stream.read()         stream.close     set stream = nothing end function  

now twitter alow authorization , media parameter, said : media type unrecognized

why?


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -