Question:
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
I'll have a look tomorrow. I've been intending to create a Twitter category on example-code.com. I'll start it tomorrow..
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..)
Twitter examples have begun: https://www.example-code.com/idx_twitter.asp
There's much much more coming..
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
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..
I added an example for tweeting w/ emoji chars. I didn't find anything special or difficult about it.. :-)
I must be doing it wrong :-/ Same code, just my own txt file (utf-8 created via Notepad++). No Emoji in tweet.
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")...
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: â¤
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');