on receiveaction_(sender)
set thetweet to tweetfield's stringValue() as string
if (thetweet's length) ≤ 140 then
set sendpass to thepassword's stringValue()
set senduser to theusername's stringValue()
tell current application's class "NSURL" to set theurl to its URLWithString_("http://" & senduser & ":" & sendpass & "@twitter.com/statuses/update.xml")
tell current application's class "NSMutableURLRequest" to set therequest to its requestWithURL_cachePolicy_timeoutInterval_(theurl, class "NSURLRequestUseProtocolCachePolicy", 60.0)
tell current application's class "NSData" to set postdata to thetweet's dataUsingEncodeing_allowLossyConversion_(class "NSASCIIStringEncodeing", false)
tell current application's class "NSString" to set postLength to (postdata's length)'s stringWithFormat_("%d")
request's setHTTPMethod_("POST")
request's setValue_forHTTPHeaderField_(postLength, "Content-Length")
request's setValue_forHTTPHeaderField_("application/x-www-form-urlencoded", "Content-Type")
request's setHTTPBody_(postdata)
end if
end receiveaction_
I’ve been working on it for a while; days; and nothing.
Constants like “NSURLRequestUseProtocolCachePolicy” don’t work in ASOC (at least they don’t for me). Try replacing “class “NSURLRequestUseProtocolCachePolicy”” with 0.
Also, I couldn’t find “dataUsingEncodeing_allowLossyConversion” in the NSData reference – it is in NSString ( also there is no “e” after the “d” in Encoding), and once again replace the constant “class “NSASCIIStringEncodeing”” with 1.
They should if you remove the quotes and precede them by "current application’s ". It makes for longer code, but it also makes it more readable later on.
Error 1 is gone… Error 2 is still there… After testing with it, I can’t get anything.
I have:
on receiveaction_(sender)
set thetweet to tweetfield's stringValue() as string
if (thetweet's length) ≤ 140 then
set sendpass to thepassword's stringValue()
set senduser to theusername's stringValue()
tell current application's class "NSURL" to set theurl to its URLWithString_("http://" & senduser & ":" & sendpass & "@twitter.com/statuses/update.xml")
tell current application's class "NSMutableURLRequest" to set therequest to its requestWithURL_cachePolicy_timeoutInterval_(theurl, 0, 60.0)
tell current application's class "NSData" to set postdata to thetweet's dataUsingEncodeing_allowLossyConversion_(1, false)
tell current application's class "NSString" to set postLength to (postdata's length)'s stringWithFormat_("%d")
request's setHTTPMethod_("POST")
request's setValue_forHTTPHeaderField_(postLength, "Content-Length")
request's setValue_forHTTPHeaderField_("application/x-www-form-urlencoded", "Content-Type")
request's setHTTPBody_(postdata)
end if
end receiveaction_
Tried… and nothing worked. I decided to do some research… and found out the variable “request” was not defined, either. :mad: OHZ NOZ!
I need help… I can’t understand this mumbo jumbo of errors and messes.
with
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 therequest to its requestWithURL_cachePolicy_timeoutInterval_(theurl, 0, 60.0)
log 3
set postdata to thetweet's dataUsingEncoding_allowLossyConversion_(class "NSASCIIStringEncodeing", false)
log 4
try
tell current application's class "NSString" to set postLength to (postdata's length)'s stringWithFormat_("%d")
end try
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_
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
set postdata to thetweet's dataUsingEncoding_allowLossyConversion_(1, false)
log 4
tell current application's class "NSString" to set postLength to (postdata's length)'s stringWithFormat_("%d")
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_
Ah! Progress! Messed stuff around. Next, the variable postLength is not defined after “6” is logged.
on receiveaction_(sender)
set thetweet to tweetfield's stringValue()
display dialog thetweet as string
if ((thetweet as string)'s length) ≤ 140 then
set sendpass to thepassword's stringValue() as string
set senduser to theusername's stringValue() as string
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 "NSString" to set postLength to (postdata's length)'s stringWithFormat_("%d") -- what does this do
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_
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”
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.
I’ll try to see what I did. Is there a class method that adds authorization to the variable request?