login about faq

Can someone help to get twitter tweet with Image getting to work?

I looked into the following Posts and ressources and this Forum:

https://dev.twitter.com/rest/media/uploading-media.html

http://www.chilkatforum.com/questions/5583/status-with-photo

https://twittercommunity.com/t/uploading-base64-encoded-image-using-1-1-media-upload-json/26983/6

I did try with OAuth1 and all Key,token for my twitter application set.

Not sure what to Change. I receive 400/403 Errors all the time.

Since Chilkat is now on Twitter I hope some People got interested in helping me getting this to work for interaction with Twitter?

My Code:

$req = new CkHttpRequest();

$req->AddParam("status","just a test");
$req->AddParam("media","e:\\test.jpg");

$resp = $http->PostUrlEncoded('https://upload.twitter.com/1.1/media/upload.json',$req);

if (is_null($resp)) {
    print $http->lastErrorText() . "\n";
    exit;
}

if ($resp->get_StatusCode() == 200) {
    //  Display the JSON response.
    print $resp->bodyStr() . "\n";
}
else {
    print $http->lastErrorText() . "\n";
}

All Looks good until this Response with error. No new Tweet on twitter at all.

domain: upload.twitter.com port: 443 ssl: 1 openHttpConnection: Opening connection directly to HTTP server. httpHostname: upload.twitter.com httpPort: 443 ssl: 1 HTTPS secure channel established. --openHttpConnection connectTime: Elapsed time: 264 millisec sendRequestHeader: sendHeaderElapsedMs: 0 --sendRequestHeader sendRequestBody: sendBodyElapsedMs: 1 --sendRequestBody statusCode: 400 statusText: Bad Request --fullHttpRequest success: 1 --a_synchronousRequest success: 1 --fullRequest Success. --PostUrlEncoded urlObject_loadUrl: --urlObject_loadUrl --ChilkatLog

asked Oct 29 at 19:09

Loki1's gravatar image

Loki1
1


12next page »

I'll have a look tomorrow. I've been intending to create a Twitter category on example-code.com. I'll start it tomorrow..

link

answered Oct 29 at 19:18

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

This is cool :) Will it be announced on cknotes blog once available?

(Oct 31 at 10:50) Loki1

Sorry for the delay. I'm starting the Twitter examples now. I'll post to the blog and also tweet about them. At first, you'll see an empty Twitter category appear on example-code.com, and then one by one you'll see examples appear. They'll begin with the most simple tasks, and then will get to something more complicated such as tweeting with an image. (I like to get the simple stuff working first, then move to progressively more difficult tasks..)

link

answered Oct 31 at 10:54

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

Twitter examples have begun: https://www.example-code.com/idx_twitter.asp

There's much much more coming..

link

answered Oct 31 at 13:16

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

Tested the examples. Good Job! I was so waiting for this :)

Maybe a chance to handle Unicode emoji in status update as well? Seems to be tricky?

Source for codes to play around with if you want: http://apps.timwhitlock.info/emoji/tables/unicode

link

answered Oct 31 at 17:49

Loki1's gravatar image

Loki1
1

Thanks.. Yes, that's no problem. I already was working on an example to verify non-usascii chars. I'll see what I can do for emoji chars..

link

answered Oct 31 at 17:51

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

I added an example for tweeting w/ emoji chars. I didn't find anything special or difficult about it.. :-)

link

answered Nov 01 at 12:09

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

I must be doing it wrong :-/ Same code, just my own txt file (utf-8 created via Notepad++). No Emoji in tweet.

link

answered Nov 01 at 15:55

Loki1's gravatar image

Loki1
1

Examine the txt file using a hex editor to see what the actual bytes are. Maybe Notepad++ tries to save as utf-16, and emoji chars require surrogate pairs for utf-16. See here: http://apps.timwhitlock.info/emoji/tables/unicode The 1st char listed at that web page is at U+1F601 (greater than 0xFFFF).

I use EmEditor (https://www.emeditor.com/) for text editing (unless I'm working in some programming IDE). It's been my favorite for many years for editing when it comes to non-English or different character encodings. It should auto-detect the char encoding, and you can "Save-As" to utf-8 or anything else (or "Reload As")...

link

answered Nov 02 at 07:29

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

I used it as following:

in my "/tweet/emoji.txt" I got this text:

❤ test1

emoji1.txt is safed as UTF-8 via EmEditor.

In my Code all is working beside the LoadString()? Which returns "true" (so it should have parsed and added the above text to the message).

$sbText = new CkStringBuilder();

$val = $sbText->LoadFile("/tweet/emoji1.txt","UTF-8"); // did try "utf8" as well
$sbText->Append("this is shown..."); // the only text showing up on tweet.

//  Send a tweet...
$rest->ClearAllQueryParams();
$rest->AddQueryParam('status',$sbText->getAsString());
$response = $rest->fullRequestFormUrlEncoded('POST','/1.1/statuses/update.json');

[EDIT]:

I changed

$val = $sbText->LoadFile("/tweet/emoji1.txt","UTF-8");

to

$val = $sbText->LoadFile("emoji1.txt","UTF-8");

I moved the file up a folder right next to the .php file, now it is loading my file, but only the text "test1" is shown. Not the heart.

Heart is showing up fine if I open the file in Notepad++ or EmEditor. Still safed as utf-8.

If I add the hearts right into my text to tweet it is displayed by twitter as: â¤

link

answered Nov 02 at 10:27

Loki1's gravatar image

Loki1
1

edited Nov 02 at 10:36

This is important to remember: The lowercase alternative methods return ANSI by default. Make sure to set the utf8 property to tell the object to return utf-8.

For example:

$sbText = new CkStringBuilder();
$sbText->put_Utf8(1);

$val = $sbText->LoadFile("/tweet/emoji1.txt","UTF-8"); // did try "utf8" as well
$sbText->Append("this is shown..."); // the only text showing up on tweet.

//  Send a tweet...
$rest->ClearAllQueryParams();
// The getAsString will return ANSI unless we told the $sbText object to return utf-8 ...
// It is not possible to represent the emoji in ANSI, therefore you must use utf-8.
// Also tell the REST object that we're passing in utf-8.
$rest->put_Utf8(1);
$rest->AddQueryParam('status',$sbText->getAsString());
$response = $rest->fullRequestFormUrlEncoded('POST','/1.1/statuses/update.json');
link

answered Nov 02 at 10:33

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

edited Nov 02 at 10:34

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×50
×35
×11
×7
×4

Asked: Oct 29 at 19:09

Seen: 228 times

Last updated: Nov 02 at 10:58

powered by OSQA