@@ -76,11 +76,16 @@ public TwitterService getService() {
76
76
}
77
77
78
78
public interface TwitterService {
79
+
80
+
79
81
@ GET ("/statuses/home_timeline.json" )
80
82
public List <Tweet > homeTimeline (@ Query ("since_id" ) String sinceId );
81
83
@ FormUrlEncoded
82
84
@ POST ("/statuses/update.json" )
83
85
public Tweet postStatus (@ Field ("status" ) String status );
86
+ @ FormUrlEncoded
87
+ @ POST ("/statuses/update.json" )
88
+ public Tweet postStatus (@ Field ("status" ) String status , @ retrofit .http .Header (CUSTOM_NONCE ) String customNonce );
84
89
@ GET ("/direct_messages.json" )
85
90
public List <DM > getReceivedDMs (@ Field ("count" ) int limit );
86
91
@ GET ("/direct_messages.json" )
@@ -95,11 +100,22 @@ public interface TwitterService {
95
100
public Tweet removeFavorite (@ Field ("id" ) String tweetId );
96
101
}
97
102
103
+ final static String CUSTOM_NONCE = "custom_nonce_field" ;
98
104
private static class WrapperClient implements Client {
99
105
OkClient okClient = new OkClient ();
100
106
WrapperClient () {
101
107
102
108
}
109
+
110
+ public String getNonce (Request request ) {
111
+ for (Header header : request .getHeaders ()) {
112
+ if (CUSTOM_NONCE .equals (header .getName ())) {
113
+ return header .getValue ();
114
+ }
115
+ }
116
+ return UUID .randomUUID ().toString ();
117
+ }
118
+
103
119
@ Override
104
120
public Response execute (Request request ) throws IOException {
105
121
if (Config .ARTIFICIAL_REQUEST_DELAY > 0 ) {
@@ -113,8 +129,7 @@ public Response execute(Request request) throws IOException {
113
129
Map <String , String > headers = new HashMap <String , String >();
114
130
headers .put ("oauth_consumer_key" , Config .CONNECTION_CONFIGURATION .consumerKey );
115
131
//TODO create proper nonce
116
-
117
- headers .put ("oauth_nonce" , UUID .randomUUID ().toString ());
132
+ headers .put ("oauth_nonce" , getNonce (request ));
118
133
headers .put ("oauth_signature_method" , "HMAC-SHA1" );
119
134
headers .put ("oauth_timestamp" , Long .toString (System .currentTimeMillis () / 1000 ));
120
135
headers .put ("oauth_token" , Config .CONNECTION_CONFIGURATION .accessToken );
@@ -207,7 +222,7 @@ public static String sha1(String s, String keyString) throws
207
222
}
208
223
209
224
private static String percentEncode (String val ) throws UnsupportedEncodingException {
210
- return Uri . encode (val , "UTF-8" );
225
+ return net . oauth . OAuth . percentEncode (val );
211
226
}
212
227
}
213
228
}
0 commit comments