-
Notifications
You must be signed in to change notification settings - Fork 25
#41 #45 Solved problem with error Check your credentials. #46
base: master
Are you sure you want to change the base?
Changes from 5 commits
c3d3cd2
e349236
c14d2d7
bd951a1
fd72b30
276d6f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ public class User { | |
| private String city; | ||
| private String displayName; | ||
| private String avatarUrl; | ||
| private String liveUsername; | ||
| private Presence presence = Presence.OFFLINE; | ||
|
|
||
| User(Skype skype, String username) { | ||
|
|
@@ -247,6 +248,14 @@ void setPresence(Presence presence, boolean triggerListeners) { | |
| } | ||
| } | ||
|
|
||
| String getLiveUsername() { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (I made these private, probably doesn't need to be in the library public api) |
||
| return liveUsername; | ||
| } | ||
|
|
||
| void setLiveUsername(String liveUsername) { | ||
| this.liveUsername = liveUsername; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| final int prime = 31; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,10 +86,12 @@ private void updateContacts() throws IOException { | |
| updated = true; | ||
| String selfResponse = sendRequest(Method.GET, "/users/self/profile").body(); | ||
| JSONObject selfJSON = new JSONObject(selfResponse); | ||
| updateUser(selfJSON, false); | ||
|
|
||
| User loggedUser = updateUser(selfJSON, false, username); | ||
|
|
||
| String profilesResponse = | ||
| sendRequest(Method.GET, "https://contacts.skype.com/contacts/v2/users/" + getSelfLiveUsername() + "/contacts", true).body(); | ||
| sendRequest(Method.GET, "https://contacts.skype.com/contacts/v2/users/" + loggedUser.getLiveUsername() + "/contacts", true).body(); | ||
|
|
||
| try { | ||
| JSONObject json = new JSONObject(profilesResponse); | ||
| if (json.optString("message", null) != null) { | ||
|
|
@@ -108,6 +110,10 @@ private void updateContacts() throws IOException { | |
| } | ||
|
|
||
| private User updateUser(JSONObject userJSON, boolean newContactType) throws ParseException { | ||
| return updateUser(userJSON, newContactType, null); | ||
| } | ||
|
|
||
| private User updateUser(JSONObject userJSON, boolean newContactType, String username) throws ParseException { | ||
| String userUsername; | ||
| String userFirstName = null; | ||
| String userLastName = null; | ||
|
|
@@ -118,7 +124,7 @@ private User updateUser(JSONObject userJSON, boolean newContactType) throws Pars | |
| String userAvatarUrl = null; | ||
| try { | ||
| if (!newContactType) { | ||
| userUsername = userJSON.getString("username"); | ||
| userUsername = userJSON.optString("username"); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code will only be executed for the current user. If username is null, userUsername will be empty, which will set the current User username to the empty string. This will request "https://contacts.skype.com/contacts/v2/users//contacts" immediately after in WebConnector.java:93, which cannot work. Set this to getString maybe? |
||
| userFirstName = userJSON.optString("firstname", null); | ||
| userLastName = userJSON.optString("lastname", null); | ||
| userMood = userJSON.optString("mood", null); | ||
|
|
@@ -146,9 +152,13 @@ private User updateUser(JSONObject userJSON, boolean newContactType) throws Pars | |
| userUsername = mri.substring(senderBegin + 1); | ||
| userDisplayName = userJSON.optString("display_name", null); | ||
| JSONObject profileJSON = userJSON.getJSONObject("profile"); | ||
| JSONObject nameJSON = profileJSON.getJSONObject("name"); | ||
| userFirstName = nameJSON.optString("first", null); | ||
| userLastName = nameJSON.optString("surname", null); | ||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed the default set-s for firstName and lastName, since when not set we should return null and let the library user decide what to do, rather than return a default value ourselves. |
||
| if (profileJSON.has("name")) { | ||
| JSONObject nameJSON = profileJSON.getJSONObject("name"); | ||
| userFirstName = nameJSON.optString("first", null); | ||
| userLastName = nameJSON.optString("surname", null); | ||
| } | ||
|
|
||
| userMood = profileJSON.optString("mood", null); | ||
| if (profileJSON.has("locations")) { | ||
| JSONObject locationJSON = profileJSON.optJSONArray("locations").optJSONObject(0); | ||
|
|
@@ -162,14 +172,15 @@ private User updateUser(JSONObject userJSON, boolean newContactType) throws Pars | |
| } catch (JSONException e) { | ||
| throw new ParseException(e); | ||
| } | ||
| User user = skype.getUser(userUsername); | ||
| User user = skype.getUser(username != null ? username : userUsername); | ||
| user.setCity(getPlaintext(userCity)); | ||
| user.setCountry(getPlaintext(userCountry)); | ||
| user.setDisplayName(getPlaintext(userDisplayName)); | ||
| user.setFirstName(getPlaintext(userFirstName)); | ||
| user.setLastName(getPlaintext(userLastName)); | ||
| user.setMood(getPlaintext(userMood)); | ||
| user.setAvatarUrl(userAvatarUrl); | ||
| user.setLiveUsername(userUsername); | ||
| return user; | ||
| } | ||
|
|
||
|
|
@@ -220,6 +231,7 @@ private Response sendRequest(Method method, String apiPath, boolean absoluteApiP | |
| logger.finest("Sending " + method + " request at " + url); | ||
| if (skypeToken != null) { | ||
| conn.header("X-Skypetoken", skypeToken); | ||
| conn.header("Accept", "application/json"); | ||
| } else { | ||
| logger.fine("No token sent for the request at: " + url); | ||
| } | ||
|
|
@@ -230,12 +242,4 @@ private Response sendRequest(Method method, String apiPath, boolean absoluteApiP | |
| private Response sendRequest(Method method, String apiPath, String... keyval) throws IOException { | ||
| return sendRequest(method, apiPath, false, keyval); | ||
| } | ||
|
|
||
| private String getSelfLiveUsername() { | ||
| if (username.contains("@")) { | ||
| return "live:" + username.substring(0, username.indexOf('@')); | ||
| } else { | ||
| return username; | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is suprising indeed, maybe they removed recently like they removed Challenge. Let's include this change for now if its works for you.