Skip to content

Commit fbffe2c

Browse files
committed
fix percent encoding
1 parent aaf2a61 commit fbffe2c

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ android {
2424
compile 'com.squareup.okhttp:okhttp:1.3.0'
2525
compile 'com.squareup.dagger:dagger:1.2.0'
2626
compile 'com.squareup.dagger:dagger-compiler:1.2.0'
27+
compile 'net.oauth.core:oauth:20100527'
2728
}
2829

2930
buildTypes {

app/src/main/java/com/birbit/android/livecode/twitter/business/TwitterApiClient.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,16 @@ public TwitterService getService() {
7676
}
7777

7878
public interface TwitterService {
79+
80+
7981
@GET("/statuses/home_timeline.json")
8082
public List<Tweet> homeTimeline(@Query("since_id") String sinceId);
8183
@FormUrlEncoded
8284
@POST("/statuses/update.json")
8385
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);
8489
@GET("/direct_messages.json")
8590
public List<DM> getReceivedDMs(@Field("count") int limit);
8691
@GET("/direct_messages.json")
@@ -95,11 +100,22 @@ public interface TwitterService {
95100
public Tweet removeFavorite(@Field("id") String tweetId);
96101
}
97102

103+
final static String CUSTOM_NONCE = "custom_nonce_field";
98104
private static class WrapperClient implements Client {
99105
OkClient okClient = new OkClient();
100106
WrapperClient() {
101107

102108
}
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+
103119
@Override
104120
public Response execute(Request request) throws IOException {
105121
if(Config.ARTIFICIAL_REQUEST_DELAY > 0) {
@@ -113,8 +129,7 @@ public Response execute(Request request) throws IOException {
113129
Map<String, String> headers = new HashMap<String, String>();
114130
headers.put("oauth_consumer_key", Config.CONNECTION_CONFIGURATION.consumerKey);
115131
//TODO create proper nonce
116-
117-
headers.put("oauth_nonce", UUID.randomUUID().toString());
132+
headers.put("oauth_nonce", getNonce(request));
118133
headers.put("oauth_signature_method", "HMAC-SHA1");
119134
headers.put("oauth_timestamp", Long.toString(System.currentTimeMillis() / 1000));
120135
headers.put("oauth_token", Config.CONNECTION_CONFIGURATION.accessToken);
@@ -207,7 +222,7 @@ public static String sha1(String s, String keyString) throws
207222
}
208223

209224
private static String percentEncode(String val) throws UnsupportedEncodingException {
210-
return Uri.encode(val, "UTF-8");
225+
return net.oauth.OAuth.percentEncode(val);
211226
}
212227
}
213228
}

0 commit comments

Comments
 (0)