Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9153575

Browse files
committed
Add getAccountId() to DbxAuthFinish.
1 parent4f08600 commit9153575

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

‎examples/authorize/src/main/java/com/dropbox/core/examples/authorize/Main.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public static void main(String[] args) throws IOException {
8787

8888
System.out.println("Authorization complete.");
8989
System.out.println("- User ID: " +authFinish.getUserId());
90+
System.out.println("- Account ID: " +authFinish.getAccountId());
9091
System.out.println("- Access Token: " +authFinish.getAccessToken());
9192

9293
// Save auth information to output file.

‎src/main/java/com/dropbox/core/DbxAuthFinish.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
publicfinalclassDbxAuthFinish {
2222
privatefinalStringaccessToken;
2323
privatefinalStringuserId;
24+
privatefinalStringaccountId;
2425
privatefinal/*@Nullable*/StringurlState;
2526

2627
/**
@@ -29,9 +30,10 @@ public final class DbxAuthFinish {
2930
* @param urlState State data passed in to {@link DbxWebAuth#start} or {@code null} if no state
3031
* was passed
3132
*/
32-
publicDbxAuthFinish(StringaccessToken,StringuserId,/*@Nullable*/StringurlState) {
33+
publicDbxAuthFinish(StringaccessToken,StringuserId,StringaccountId,/*@Nullable*/StringurlState) {
3334
this.accessToken =accessToken;
3435
this.userId =userId;
36+
this.accountId =accountId;
3537
this.urlState =urlState;
3638
}
3739

@@ -47,14 +49,24 @@ public String getAccessToken() {
4749

4850
/**
4951
* Returns the Dropbox user ID of the user who just approved your app for access to their
50-
* Dropbox account.
52+
* Dropbox account. We use user ID to identify user in API V1.
5153
*
5254
* @return Dropbox user ID of user that approved your app for access to their account
5355
*/
5456
publicStringgetUserId() {
5557
returnuserId;
5658
}
5759

60+
/**
61+
* Returns the Dropbox account ID of the user who just approved your app for access to their
62+
* Dropbox account. We use account ID to identify user in API V2.
63+
*
64+
* @return Dropbox account ID of user that approved your app for access to their account
65+
*/
66+
publicStringgetAccountId() {
67+
returnaccountId;
68+
}
69+
5870
/**
5971
* Returns the state data you passed in to {@link DbxWebAuth#start}. If you didn't pass
6072
* anything in, or you used {@link DbxWebAuthNoRedirect}, this will be {@code null}.
@@ -76,7 +88,7 @@ DbxAuthFinish withUrlState(/*@Nullable*/ String urlState) {
7688
if (this.urlState !=null) {
7789
thrownewIllegalStateException("Already have URL state.");
7890
}
79-
returnnewDbxAuthFinish(accessToken,userId,urlState);
91+
returnnewDbxAuthFinish(accessToken,userId,accountId,urlState);
8092
}
8193

8294
/**
@@ -89,6 +101,7 @@ public DbxAuthFinish read(JsonParser parser) throws IOException, JsonReadExcepti
89101
StringaccessToken =null;
90102
StringtokenType =null;
91103
StringuserId =null;
104+
StringaccountId =null;
92105
Stringstate =null;
93106

94107
while (parser.getCurrentToken() ==JsonToken.FIELD_NAME) {
@@ -105,6 +118,9 @@ else if (fieldName.equals("access_token")) {
105118
elseif (fieldName.equals("uid")) {
106119
userId =JsonReader.StringReader.readField(parser,fieldName,userId);
107120
}
121+
elseif (fieldName.equals("account_id")) {
122+
accountId =JsonReader.StringReader.readField(parser,fieldName,accountId);
123+
}
108124
elseif (fieldName.equals("state")) {
109125
state =JsonReader.StringReader.readField(parser,fieldName,state);
110126
}
@@ -123,8 +139,9 @@ else if (fieldName.equals("state")) {
123139
if (tokenType ==null)thrownewJsonReadException("missing field\"token_type\"",top);
124140
if (accessToken ==null)thrownewJsonReadException("missing field\"access_token\"",top);
125141
if (userId ==null)thrownewJsonReadException("missing field\"uid\"",top);
142+
if (accountId ==null)thrownewJsonReadException("missing field\"account_id\"",top);
126143

127-
returnnewDbxAuthFinish(accessToken,userId,state);
144+
returnnewDbxAuthFinish(accessToken,userId,accountId,state);
128145
}
129146
};
130147

‎src/test/java/com/dropbox/core/DbxWebAuthTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,17 @@ public void testFinishWithState() throws Exception {
150150

151151
assertNotNull(sessionStore.get());
152152

153-
DbxAuthFinishexpected =newDbxAuthFinish("test-access-token","test-user-id",state);
153+
DbxAuthFinishexpected =newDbxAuthFinish(
154+
"test-access-token","test-user-id","test",state
155+
);
154156
ByteArrayOutputStreambody =newByteArrayOutputStream();
155157
ByteArrayInputStreamresponseStream =newByteArrayInputStream(
156158
(
157159
"{" +
158160
"\"token_type\":\"Bearer\"" +
159161
",\"access_token\":\"" +expected.getAccessToken() +"\"" +
160162
",\"uid\":\"" +expected.getUserId() +"\"" +
163+
",\"account_id\":\"" +expected.getAccountId() +"\"" +
161164
"}"
162165
).getBytes("UTF-8")
163166
);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp