Reputation: 639
I have the following test line in my PHP which works fine as a way of posting to Twitter from within my PHP code.
$oauth->post('statuses/update', array('status' => "hello world"));
However I want to post the contents of a variable as opposed to Hello World
If I change the code as follows, then all that gets posted is $message
$oauth->post('statuses/update', array('status' => '$message'));
I also tried without the ' but then nothing got posted, ie
$oauth->post('statuses/update', array('status' => $message));
How can I correctly parse the contents of $message?
$message is created as follows
$message = "http://www.smartphonesoft.com/index.php?option=com_mtree&task=viewlink&link_id=" .$link_id . " " ."Windows Phone Software" . " " .$link_name . " " . $metadesc;
I added an echo $message which showed me what I expected, namely:
http://www.smartphonesoft.com/index.php?option=com_mtree&task=viewlink&link_id=33183073 Windows Phone Software Pocket Player Pocket Player is a rockin' way to enjoy music and video on your Windows Mobile device. Through multiple media and playlist formats, Internet connectivity, plugin extensions, and an intuitive interface, Pocket Player means less taps, more music!
Thanks,
Greg
Upvotes: 0
Views: 407
Reputation: 407
Since your URL is way too long for twitter, perhaps you'd like to shorten the url before posting it.
The bit.ly API documentation page will help you set up an account and your own api key.
You could then either devise your own code from the official documentation or follow this bit.ly api tutorial by David Walsh
Upvotes: 0
Reputation: 316989
From the Twitter API doc for status/update:
status
The text of your status update, up to 140 characters. URL encode as necessary.So I'd say you have to shorten the $message
, because yours has 369 characters.
Upvotes: 3
Reputation: 10265
'$message'
can't work because you're actually passing the string "'$message'"
, and not the $message
variable.
If the second code you posted doesn't work, it's either because $message
is not defined in your script, or because something else in your script is wrong, but we can't really tell that without seeing the rest of the code.
Upvotes: 0
Reputation: 169051
The last code you quote is correct. Are you sure $message
has meaningful content?
(Aside: The reason for '$message'
posting "$message" verbatim is that single-quoted strings in PHP do not get variable interpolation nor escape characters: '\n'
is literally "\n", whereas "\n"
would result in a string containing the newline character.)
Upvotes: 1