我正在尝试用 Vala 制作一个简单的 Twitter 应用程序。我正在使用 Vala Rest 绑定(librest-dev v0.7)。一切正常,直到我尝试初始化一个OAuthProxyCall
,此时我从 vala 编译器得到这个 C 错误:
someone@someone-UBook:~/workspace/vala/twitter$ valac --pkg rest-0.7 TwitterAuthTest.vala -o authtest
/home/someone/workspace/vala/twitter/TwitterAuthTest.vala.c: In function ‘twitter_auth_test_main’:
/home/someone/workspace/vala/twitter/TwitterAuthTest.vala.c:206:10: warning: assignment makes pointer from integer without a cast [enabled by default]
/tmp/ccEzeuFy.o: In function `twitter_auth_test_main':
TwitterAuthTest.vala.c:(.text+0x4a8): undefined reference to `oauth_proxy_call_new'
collect2: ld returned 1 exit status
error: cc exited with status 256
Compilation failed: 1 error(s), 0 warning(s)
这是我尽可能简单的代码:
using Rest;
public class TwitterAuthTest {
private static const string CONSUMER_KEY = "XXXXXXXXXXXXXXXXXXXXXX";
private static const string CONSUMER_SECRET = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
private static const string URL_FORMAT = "https://api.twitter.com";
private static const string REQUEST_TOKEN_URL = "https://api.twitter.com/oauth/request_token";
private static const string FUNCTION_ACCESS_TOKEN = "oauth/access_token";
private static const string FUNCTION_STATUSES_UPDATE = "statuses/update.xml";
private static const string PARAM_STATUS = "status";
public static int main(string[] args) {
// initialize proxy
var proxy = new OAuthProxy(CONSUMER_KEY, CONSUMER_SECRET, URL_FORMAT, false); // false = url doesn't require expansion
// request token
try {
proxy.request_token("oauth/request_token", "oob");
} catch (Error e) {
stderr.printf("Couldn't get request token: %s\n", e.message);
}
// prompt user for pin
stdout.printf("Go to http://twitter.com/oauth/authorize?oauth_token=%s then enter the PIN\n", proxy.get_token());
string pin = stdin.read_line(); //3001930
// access token
try { proxy.access_token(FUNCTION_ACCESS_TOKEN, pin); }
catch (Error e) {
stderr.printf("Couldn't get access token: %s\n", e.message);
}
// setup call
OAuthProxyCall call = new OAuthProxyCall();
call.set_function(FUNCTION_STATUSES_UPDATE);
call.add_param(PARAM_STATUS, "Hello from librest!");
try { call.sync(); } catch (Error e) {
stderr.printf("Cannot make call: %s\n", e.message);
}
return 0;
}
}
我对 REST/OAUTH 完全不熟悉——我需要如何设置我的 OAuthProxyCall 才能正确编译?