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

Media upload is not supported.! #9

Open
shrinath-shenoy opened this issue Dec 15, 2015 · 3 comments
Open

Media upload is not supported.! #9

shrinath-shenoy opened this issue Dec 15, 2015 · 3 comments

Comments

@shrinath-shenoy
Copy link

Looks like ngTwitter doesnot support media upload. Also the post calls are appended with get parameters which is not correct -

// // Append the bodyparams to the URL
var t = $twitterHelpers.createTwitterSignature('POST', url, parameters, clientId, clientSecret, token);
if (parameters !== {}) url = url + '?' + $twitterHelpers.transformRequest(parameters);

@saimon24
Copy link
Owner

Post request has worked for me all the time, guess it's a special problem with the media upload. Feel free to make the changes to the body params and submit a pull request, I would be happy to merge it!

@shagul298
Copy link

Can u share your code for media upload post request.....

@ghost
Copy link

ghost commented Aug 23, 2017

I'm having the same trouble, i can't upload an image using POST api with media_id on body request.

I checked the code, and what I understood is that even when make a POST call this part of code adds to url request the params (optional data):

if (parameters !== {}) url = url + '?' + $twitterHelpers.transformRequest(parameters);

This solution is ok when url characters does not exceed the maximum numbers of characters on a HTTP call, but when media_id is too long the call fails.

Could anybody can confirm this?

This is the code i'm using but without success:

    var oauthObject = {
      oauth_consumer_key: clientId,
      oauth_nonce: $cordovaOauthUtility.createNonce(32),
      oauth_signature_method: "HMAC-SHA1",
      oauth_token: token.oauth_token,
      oauth_timestamp: Math.round((new Date()).getTime() / 1000.0),
      oauth_version: "1.0"
    };

    var signatureObj = $cordovaOauthUtility.createSignature("POST", url,
                      oauthObject, {screen_name: token.screen_name}, clientSecret,
                      token.oauth_token_secret);

    $http.defaults.headers.common.Authorization = signatureObj.authorization_header;

    console.log(JSON.stringify(signatureObj));

    var _headers = {
      'Authorization': signatureObj.authorization_header,
      'Content-Type': 'application/x-www-form-urlencoded'
    };

    $http({
      method: "post",
      url: "https://upload.twitter.com/1.1/media/upload.json",
      data: JSON.stringify(base64String)
    }).success(function(data, status, headers, config) {
        console.log(data);
        deferred.resolve(data);
      })
      .error(function(data, status, headers, config) {
        console.log(data);
        deferred.reject(status);
      });

I have tested using both endpoint:


This is the result i got:

Request URL:https://upload.twitter.com/1.1/media/upload.json
Request Method:POST
Status Code:401 Authorization Required
Request Headers
POST https://upload.twitter.com/1.1/media/upload.json HTTP/1.1
Accept: application/json, text/plain, /
Origin: file://
User-Agent: Mozilla/5.0 (Linux; Android 4.4.2; LG-V500 Build/KOT49I.V50020f) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Safari/537.36
Authorization: OAuth oauth_consumer_key="TG*********",oauth_nonce="yyBpmX9yienaHw0xe0izomB3Fp4zCQA0",oauth_signature_method="HMAC-SHA1",oauth_token="191362************",oauth_timestamp="1503497329",oauth_version="1.0",oauth_signature="M8cv3Att*********"
Content-Type: application/json;charset=UTF-8
Request Payloadview source
{,…}
media_data: "iv0 + long base64 string"
Response Headers
content-encoding:gzip
content-length:89
content-type:application/json; charset=utf-8
date:Wed, 23 Aug 2017 14:08:47 GMT
server:tsa_f
strict-transport-security:max-age=631138519
vary:Origin
x-connection-hash:c8db7d4f36b7340e16d86e5930b43a6a
x-content-type-options:nosniff
x-frame-options:SAMEORIGIN
x-response-time:126
x-tsa-request-body-time:1
x-xss-protection:1; mode=block

Thank you in advance.

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

No branches or pull requests

3 participants