Posting with cURL withOUT the command line?

The AppleScript code is pseudo code. As the class «data .» is an abstract class,
it doesn’t respond to the length or count command.
You have to perform the task with ObjC methods.
I guess you have to declare postData as a NSData object with tell current application’s class “NSData”

I’ll look in the documentation.

YES! No errors, but I must be missing something because it didn’t post anything. Is my method of authorization (ex “http://dylanweber:password@twitter.com/statues/update.xml”) right?

on receiveaction_(sender)
		set thetweet to tweetfield's stringValue()
		log thetweet as string
		if ((thetweet as string)'s length) ≤ 140 then
			set sendpass to thepassword's stringValue()
			set senduser to theusername's stringValue()
			log 1
			tell current application's class "NSURL" to set theurl to its URLWithString_("http://" & senduser & ":" & sendpass & "@twitter.com/statuses/update.xml")
			log 2
			tell current application's class "NSMutableURLRequest" to set request to its requestWithURL_cachePolicy_timeoutInterval_(theurl, 0, 60.0)
			log 3
			set postdata to thetweet's dataUsingEncoding_allowLossyConversion_(1, false)
			log 4
			tell current application's class "NSData" to set postLength to postdata's |length|() as string
			log 5
			request's setHTTPMethod_("POST")
			log 6
			request's setValue_forHTTPHeaderField_(postLength, "Content-Length")
			log 7
			request's setValue_forHTTPHeaderField_("application/x-www-form-urlencoded", "Content-Type")
			log 8
			request's setHTTPBody_(postdata)
			log 9
		end if
	end receiveaction_

as mentioned a few times, my knowledge of ASOC syntax is almost nil, but try this


on receiveaction_(sender)
		set thetweet to tweetfield's stringValue() as string
		display dialog thetweet
		if (thetweet's length) ≤ 140 then
			set sendpass to thepassword's stringValue()
			set senduser to theusername's stringValue()
			log 1
			tell current application's class "NSURL" to set theurl to its URLWithString_("http://" & senduser & ":" & sendpass & "@twitter.com/statuses/update.xml")
			log 2
			tell current application's class "NSMutableURLRequest" to set request to its requestWithURL_cachePolicy_timeoutInterval_(theurl, 0, 60.0)
			log 3
			tell current application's class "NSData" to set postdata to thetweet's dataUsingEncoding_allowLossyConversion_(1, false)
			log 4
			tell current application's class "NSString" to set postLength to NSString's stringWithFormat_("%d", postdata's length)
			log 5
			request's setHTTPMethod_("POST")
			log 6
			request's setValue_forHTTPHeaderField_(postLength, "Content-Length")
			log 7
			request's setValue_forHTTPHeaderField_("application/x-www-form-urlencoded", "Content-Type")
			log 8
			request's setHTTPBody_(postdata)
			log 9
		end if
	end receiveaction_

Stefan, I think that brought back all of the old errors. :confused:
I’ll try to see what I did. Is there a class method that adds authorization to the variable request?

On the twitter site http://apiwiki.twitter.com/, it says:
IMPORTANT: Basic authentication removal is going to occur on August 16, 2010

This means you need to switch to OAuth for the authorization.
Curl will stop working on Aug 16.

Why reinventing the wheel anyway? Twitter has got an API for almost every language.
There are two for Cocoa: http://dev.twitter.com/pages/libraries#objectivec

Craig, you just saved me time… instead of wasting it redoing it.
Stefan, I’ve seen those before, I just wanted to make a few lines of code instead of adding 250 class files that I only need 1 or 2 for.

I’ll see what’s to trim off and what’s to love about those.

I added MGTwitterEngine by Matt Gemmell and tweaked a few things. What should I do next?

Project 2.3 MB

Sorry, I can’t help, because I’m on 10.5.8

Oh, no wonder you can’t “speak” ASOC. Anyone else? I’m not sure what to do.