Compare commits
1 commit
Author | SHA1 | Date | |
---|---|---|---|
![]() |
88a37477fe |
3 changed files with 26 additions and 5 deletions
17
Constants.h
17
Constants.h
|
@ -14,6 +14,10 @@
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef USE_TWITTER
|
||||||
|
|
||||||
|
#define API_URL @"http://api.twitter.com/1/"
|
||||||
#define OAUTH_CONSUMER_KEY @"JPmU8KJhiBKfpohCiWLg"
|
#define OAUTH_CONSUMER_KEY @"JPmU8KJhiBKfpohCiWLg"
|
||||||
#define OAUTH_CONSUMER_SECRET @"jtfSrnDrRcUnL1nqTMcAW0055m63EMClmkxhiBjQ"
|
#define OAUTH_CONSUMER_SECRET @"jtfSrnDrRcUnL1nqTMcAW0055m63EMClmkxhiBjQ"
|
||||||
#define OAUTH_SIGNATURE_METHOD @"HMAC-SHA1"
|
#define OAUTH_SIGNATURE_METHOD @"HMAC-SHA1"
|
||||||
|
@ -22,6 +26,19 @@
|
||||||
#define OAUTH_ACCESS_TOKEN_URL @"http://twitter.com/oauth/access_token"
|
#define OAUTH_ACCESS_TOKEN_URL @"http://twitter.com/oauth/access_token"
|
||||||
#define OAUTH_SERVICE_NAME @"twitter.com"
|
#define OAUTH_SERVICE_NAME @"twitter.com"
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#define API_URL @"http://identi.ca/api/"
|
||||||
|
#define OAUTH_CONSUMER_KEY @"76cb48ce4c65a9c760078b60aa9ce18f"
|
||||||
|
#define OAUTH_CONSUMER_SECRET @"519f5624b2024983369371b2ba389591"
|
||||||
|
#define OAUTH_SIGNATURE_METHOD @"HMAC-SHA1"
|
||||||
|
#define OAUTH_REQUEST_TOKEN_URL @"http://identi.ca/api/oauth/request_token"
|
||||||
|
#define OAUTH_USER_AUTHORIZATION_URL @"http://identi.ca/api/oauth/authorize"
|
||||||
|
#define OAUTH_ACCESS_TOKEN_URL @"http://identi.ca/api/oauth/access_token"
|
||||||
|
#define OAUTH_SERVICE_NAME @"identi.ca"
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#define APP_NAME @"Twittia"
|
#define APP_NAME @"Twittia"
|
||||||
#define TWEET_MAX_LENGTH 140
|
#define TWEET_MAX_LENGTH 140
|
||||||
|
|
||||||
|
|
8
OAuth.m
8
OAuth.m
|
@ -27,7 +27,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
-(id)init {
|
-(id)init {
|
||||||
if (self = [super init]) {
|
if ((self = [super init])) {
|
||||||
self.consumerToken = [[OAToken alloc] initWithKey:OAUTH_CONSUMER_KEY secret:OAUTH_CONSUMER_SECRET];
|
self.consumerToken = [[OAToken alloc] initWithKey:OAUTH_CONSUMER_KEY secret:OAUTH_CONSUMER_SECRET];
|
||||||
self.accessToken = [[OAToken alloc] initWithUserDefaultsUsingServiceProviderName:OAUTH_SERVICE_NAME prefix:APP_NAME];
|
self.accessToken = [[OAToken alloc] initWithUserDefaultsUsingServiceProviderName:OAUTH_SERVICE_NAME prefix:APP_NAME];
|
||||||
consumer = [[OAConsumer alloc] initWithKey:OAUTH_CONSUMER_KEY secret:OAUTH_CONSUMER_SECRET];
|
consumer = [[OAConsumer alloc] initWithKey:OAUTH_CONSUMER_KEY secret:OAUTH_CONSUMER_SECRET];
|
||||||
|
@ -59,8 +59,10 @@
|
||||||
signatureProvider:nil]; // use the default method, HMAC-SHA1
|
signatureProvider:nil]; // use the default method, HMAC-SHA1
|
||||||
|
|
||||||
[request setHTTPMethod:@"POST"];
|
[request setHTTPMethod:@"POST"];
|
||||||
|
[request setOAuthParameterName:@"oauth_callback" withValue:@"oob"];
|
||||||
|
|
||||||
OADataFetcher *fetcher = [[OADataFetcher alloc] init];
|
OADataFetcher *fetcher = [[OADataFetcher alloc] init];
|
||||||
|
NSLog(@"%@", request);
|
||||||
|
|
||||||
[fetcher fetchDataWithRequest:request
|
[fetcher fetchDataWithRequest:request
|
||||||
delegate:self
|
delegate:self
|
||||||
|
@ -69,6 +71,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)requestTokenTicket:(OAServiceTicket *)ticket didFinishWithData:(NSData *)data {
|
- (void)requestTokenTicket:(OAServiceTicket *)ticket didFinishWithData:(NSData *)data {
|
||||||
|
NSLog(@"succ: %i %@", ticket.didSucceed, ticket.response);
|
||||||
if (ticket.didSucceed) {
|
if (ticket.didSucceed) {
|
||||||
NSString *responseBody = [[NSString alloc] initWithData:data
|
NSString *responseBody = [[NSString alloc] initWithData:data
|
||||||
encoding:NSUTF8StringEncoding];
|
encoding:NSUTF8StringEncoding];
|
||||||
|
@ -76,6 +79,7 @@
|
||||||
|
|
||||||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@?oauth_token=%@", OAUTH_USER_AUTHORIZATION_URL, requestToken.key]];
|
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@?oauth_token=%@", OAUTH_USER_AUTHORIZATION_URL, requestToken.key]];
|
||||||
[[NSWorkspace sharedWorkspace] openURL:url];
|
[[NSWorkspace sharedWorkspace] openURL:url];
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,7 +138,7 @@
|
||||||
|
|
||||||
NSLog(@"%@ %@", tweet, statusId);
|
NSLog(@"%@ %@", tweet, statusId);
|
||||||
|
|
||||||
NSURL *url = [NSURL URLWithString:@"http://api.twitter.com/1/statuses/update.json"];
|
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@statuses/update.json", API_URL]];
|
||||||
OAMutableURLRequest *request = [[OAMutableURLRequest alloc] initWithURL:url
|
OAMutableURLRequest *request = [[OAMutableURLRequest alloc] initWithURL:url
|
||||||
consumer:consumer
|
consumer:consumer
|
||||||
token:accessToken
|
token:accessToken
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
// Licence: BSD (see attached LICENCE.txt file).
|
// Licence: BSD (see attached LICENCE.txt file).
|
||||||
//
|
//
|
||||||
|
|
||||||
API_PATH = "http://api.twitter.com/1/";
|
//API_PATH = "http://api.twitter.com/1/";
|
||||||
//API_PATH = "http://identi.ca/api/";
|
API_PATH = "http://identi.ca/api/";
|
||||||
|
|
||||||
function Twittia(action) {
|
function Twittia(action) {
|
||||||
this.max_length = 100;
|
this.max_length = 100;
|
||||||
|
@ -252,7 +252,7 @@ Twittia.prototype.getNewData = function(supress_new_with_timeout) {
|
||||||
/*
|
/*
|
||||||
Twittia.prototype.sendNewTweet = function(tweet, in_reply_to_status_id) {
|
Twittia.prototype.sendNewTweet = function(tweet, in_reply_to_status_id) {
|
||||||
|
|
||||||
var url = "http://api.twitter.com/1/statuses/update.json";
|
var url = API_PATH + "statuses/update.json";
|
||||||
var data = "source=twittia&status=" + OAuth.percentEncode(tweet);
|
var data = "source=twittia&status=" + OAuth.percentEncode(tweet);
|
||||||
if(in_reply_to_status_id != '') data += "&in_reply_to_status_id=" + in_reply_to_status_id
|
if(in_reply_to_status_id != '') data += "&in_reply_to_status_id=" + in_reply_to_status_id
|
||||||
|
|
||||||
|
|
Reference in a new issue