I’m trying to make a PHP script that can post to groups on Sina Weibo, a Chinese Twitter clone. Other than group functionality, Weibo seems pretty much identical to Twitter in implementation (even in API) — hence I’m mentioning Twitter as the analogy, as the distinction’s irrelevant for my question.
I can make regular posts by API just fine, but the thing is, Weibo’s API does not support posting to groups, presumably due to potential spamming hazards that might entail. (Note: my intention wasn’t to spam millions with crap, but to get a script to automatically post info on patent expiries to relevant industry groups each day.)
Now, I know there should be a work-around, as there’s an application that allows one to manually post to groups (新浪微群自动群发精灵), though the source is private. So I tried to check the post form data sent to the server using Firebug to see if I could replace the API tweet command by manually making the PHP script replicate the post form info, but to no avail.
Here is my code for the callback.php file, called after establishing the OAuth connection. The working API method to post an update has been commented out in favor of the dysfunctional post form method (in HTML tags).
<?php
session_start();
include_once( 'config.php' );
include_once( 'saetv2.ex.class.php' );
$o = new SaeTOAuthV2( WB_AKEY , WB_SKEY );
if (isset($_REQUEST['code'])) {
$keys = array();
$keys['code'] = $_REQUEST['code'];
$keys['redirect_uri'] = WB_CALLBACK_URL;
try { $token = $o->getAccessToken( 'code', $keys ) ; } catch (OAuthException $e) {}
}
if ($token) {
$_SESSION['token'] = $token;
setcookie( 'weibojs_'.$o->client_id, http_build_query($token) );
?><html><head></head><body>
<form action="http://www.weibo.com/aj/mblog/add?__rnd=1340066897833" method="post">
<input type="hidden" name="_surl" value="">
<input type="hidden" name="_t" value=0>
<input type="hidden" name="location" value="home">
<input type="hidden" name="module" value="stissue">
<input type="hidden" name="pic_id" value="">
<input type="hidden" name="rank" value="">
<input type="text" name="text" value="测试发表微博 test message" />
<input type="submit">
</form></body></html><?
/*
$c = new SaeTClientV2( WB_AKEY , WB_SKEY , $_SESSION['token']['access_token'] );
$msg = $c->update("测试发表微博 test message");
if ($msg === false || $msg === null){ echo "Error occured"; return false;}
if (isset($msg['error_code']) && isset($msg['error'])){ echo ('Error_code: '.$msg['error_code'].'; Error: '.$msg['error'] ); return false;}
echo($msg['id']." : ".$msg['text']." ".$msg["created_at"]);
*/
} else echo('授权失败。 authentication failed');
?>
I’m pretty new to all of this, so I’m probably missing something obvious, but would anyone here know enough about Twitter/Weibo to locate the problem here? Would there perhaps be an easy workaround?
Thanks!
Been a while, but for anyone stumbling upon this thread: by now I caught up a bit, and it seems like browser automation with Ruby gem Watir would have much better chances of working than form spoofing.