Posts: 1,271
Threads: 399
Joined: Mar 2003
please help me with translating the following c# code to qm.
Macro
[OperationContract]
public void SubmitUserStatus( string username, string tweet)
{
, // encode the username/password
, string user = Convert.ToBase64String( System.Text.Encoding.UTF8.GetBytes( username + ":" + password));
, // determine what we want to upload as a status
, byte [] bytes = System.Text.Encoding.ASCII.GetBytes( "status=" + tweet);
, // connect with the update page
, HttpWebRequest request = ( HttpWebRequest) WebRequest.Create( "http://twitter.com/statuses/update.xml" );
, // set the method to POST
, request.Method = "POST" ;
, // thanks to argodev for this recent change!
, request.ServicePoint.Expect100Continue = false;
, // set the authorisation levels
, request.Headers.Add( "Authorization" , "Basic " + user);
, request.ContentType = "application/x-www-form-urlencoded" ;
, // set the length of the content
, request.ContentLength = bytes.Length;
, // set up the stream
, Stream reqStream = request.GetRequestStream();
, // write to the stream
, reqStream.Write( bytes, 0 , bytes.Length);
, // close the stream
, reqStream.Close();
}
i need a small dialog or toolbar where i can drag text to for sending short messages.
Attached Files
Image(s)
Posts: 1,271
Threads: 399
Joined: Mar 2003
i love the idea to have micro blogging tools.
with win T i will show my twigger client.
Posts: 12,095
Threads: 142
Joined: Dec 2002
Function
TwitterSubmitUserStatus
;/
function $ username $ password $ tweet
str user.encrypt( 4 _s.from( username ":" password) "" 3 )
str status.from( "status=" tweet)
Http h.Connect( "twitter.com" )
h.Post( "statuses/update.xml" status 0 _s.from( "Authorization: Basic " user))
err + end _error
not tested
Posts: 1,271
Threads: 399
Joined: Mar 2003
Posts: 1,271
Threads: 399
Joined: Mar 2003
i use it now with F12.
twelve and twitter sounds similar.
currently i allow only text selection for it.
but it would be nice to have more control about selection.
its really funny to post short liners to twitter.
Posts: 1,000
Threads: 253
Joined: Feb 2008
Using XP I can not get this to work.
QM does not return an error message, but no update seems to be sent to my twitter account.
Am I missing a step?
Thanks,
Jimmy Vig
Posts: 1,000
Threads: 253
Joined: Feb 2008
I don't get an error even when the password or username are incorrect.
I know the code runs because I put a debug output text at the end and that prints in QM.
Is there something more I need to know about this that I am missing or does it just not work on XP?
Thanks,
jimmy vig.
Posts: 12,095
Threads: 142
Joined: Dec 2002
When I tested on Vista, also did not work, and no error. Don't know why.
Posts: 1,271
Threads: 399
Joined: Mar 2003
i just made a test on xp and it works.
http://twitter.com/deskareas
Function
twittertest
Trigger F12
spe - 1
str txt.getsel
if txt.len> 0
,
, tweet txt
Function tweet
;/
function $ text [$ username] [$ password]
username= "myusername"
password= "mypassword"
str user.encrypt( 4 _s.from( username ":" password) "" 3 )
str status.from( "status=" text)
Http h.Connect( "twitter.com" )
h.Post( "statuses/update.xml" status 0 _s.from( "Authorization: Basic " user))
Posts: 1,271
Threads: 399
Joined: Mar 2003
how do i add X-Twitter-Client to h.post?
X-Twitter-Client: QuickMacros
X-Twitter-Client-Url:
Twitter
X-Twitter-Client-Version: 0.1
this does not work:
h.Post
( "statuses/update.xml" status
0 _s.from
( "Authorization: Basic " user
" ,X-Twitter-Client:QuickMacros" ))
example php curl code (pasted to qm to get colored code :mrgreen: )
$ headers
= array
( "X-Twitter-Client" => "Auto Tweet" , "X-Twitter-
Client
- Version
" => " 1.1 ", " X
- Twitter
- Client
- URL
" => " http
: //
feastofcrumbs.com
/ downloads
/ wp
- plugins
/ auto
- tweet / auto
- tweet .xml
");
$ curl_handle
= curl_init
();
curl_setopt
( $ curl_handle
, CURLOPT_URL
, "$twitter_rest" );
curl_setopt
( $ curl_handle
, CURLOPT_HTTPHEADER
, $ headers
);
curl_setopt
( $ curl_handle
, CURLOPT_CONNECTTIMEOUT
, 2 );
curl_setopt
( $ curl_handle
, CURLOPT_RETURNTRANSFER
, 1 );
curl_setopt
( $ curl_handle
, CURLOPT_POST
, 1 );
curl_setopt
( $ curl_handle
, CURLOPT_POSTFIELDS
, "status=$content" );
curl_setopt
( $ curl_handle
, CURLOPT_USERPWD
, "$username:$password" );
$ buffer
= curl_exec
( $ curl_handle
);
curl_close
( $ curl_handle
);
Posts: 12,095
Threads: 142
Joined: Dec 2002
http headers must be separated by newlines, not commas, i'm sure you know
Posts: 1,000
Threads: 253
Joined: Feb 2008
I've put in exactly the example for this twitter post and cannot get it to work yet.
Is there a format that I need to put into the tweet text that tells twitter how to run it?
Thanks,
Jimmy Vig
Posts: 1,271
Threads: 399
Joined: Mar 2003
this function works for me
Function
tweetTest
;;/
function $ text [$ username] [$ password]
text= "viva la qm 2"
username= "username"
password= "password"
str user.encrypt( 4 _s.from( username ":" password) "" 3 )
_s.from( "Authorization: Basic " user)
str header.format( "%s[]X-Twitter-Client: QuickMacros" _s)
str status.from( "status=" text)
Http h.Connect( "twitter.com" )
h.Post( "statuses/update.xml" status 0 header)
out header
Posts: 1,000
Threads: 253
Joined: Feb 2008
Copied it just like that...put in my username and password...nothing...no error, just the output.
Is there something I have to set in Twitter?
Thanks for sticking through so far with me on this
Did you maybe install something that allows you to run this function properly that you haven't outlined well in this thread?
I've tested on a few different machines with no success.
Thanks,
Jimmy Vig
Posts: 46
Threads: 10
Joined: Aug 2010
I tried to use the codes for my twitter account, but it doesnt work.
Are there any parts missing? :oops:
How can i make a Tweet function that works by Dialog?
(inclusive saved login information)
And one more question:
How can i give a button a name stored in a variable?
(The variable should be saved (if password then encrypted) in a .txt or ini file for name and password)
Thanks in Advance for any help!
Posts: 12,095
Threads: 142
Joined: Dec 2002
Twitter now does not support Basic authentication. Need OAuth. Quite difficult to set up. Need to register application and learn much.
http://dev.twitter.com/doc
Posts: 46
Threads: 10
Joined: Aug 2010
Ok, i see that its easier to log in manually. :mrgreen: