-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set up v1.1 POST media/upload and tweeting with media ids
- Loading branch information
1 parent
88ab432
commit c1f5407
Showing
3 changed files
with
74 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import xnim/utils/xapi, | ||
xnim/v2/tweets | ||
xnim/v2/tweets, | ||
xnim/v1_1/media | ||
|
||
|
||
|
||
export xapi, tweets | ||
export xapi, tweets, media |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import std/[httpclient, strformat, json, times, mimetypes] | ||
import ../utils/[xapi, oauth1] | ||
|
||
const MEDIA_ENDPOINT*: string = "https://upload.twitter.com/1.1/media/upload.json" | ||
|
||
proc PostMedia*(xAPI: XAPI, fileName: string): string = | ||
|
||
var client: HttpClient = newHttpClient() | ||
var oauthNonce: string = OauthNonce() | ||
var timeStamp: int = toInt(epochTime()) | ||
var oauthSignature:string = OauthSignature(xApi, "POST", MEDIA_ENDPOINT, fileName, oauthNonce, timeStamp) | ||
var AUTH_STRING: string = | ||
&"OAuth oauth_consumer_key=\"{xAPI.consumerKey}\"," & | ||
&"oauth_token=\"{xAPI.accessToken}\"," & | ||
&"oauth_signature_method=\"HMAC-SHA1\"," & | ||
&"oauth_timestamp=\"{timeStamp}\"," & | ||
&"oauth_nonce=\"{oauthNonce}\"," & | ||
&"oauth_version=\"1.0\"," & | ||
&"oauth_signature=\"{oauthSignature}\"" | ||
|
||
|
||
client.headers = newHttpHeaders({"Content-Type": "multipart/form-data", | ||
"authorization": AUTH_STRING}) | ||
|
||
var multipart = newMultipartData() | ||
multipart.addFiles({"media": fileName}) | ||
|
||
|
||
var response: Response | ||
try: | ||
response = client.request(MEDIA_ENDPOINT, | ||
httpMethod = HttpPost, multipart=multipart) | ||
result = response.body | ||
finally: | ||
client.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters