|
22 | 22 | import com.facebook.CallbackManager;
|
23 | 23 | import com.facebook.FacebookCallback;
|
24 | 24 | import com.facebook.FacebookException;
|
| 25 | +import com.facebook.FacebookRequestError; |
25 | 26 | import com.facebook.FacebookSdk;
|
26 | 27 | import com.facebook.GraphRequest;
|
27 | 28 | import com.facebook.GraphResponse;
|
@@ -125,12 +126,24 @@ public void onSuccess(final LoginResult loginResult) {
|
125 | 126 | new GraphRequest.GraphJSONObjectCallback() {
|
126 | 127 | @Override
|
127 | 128 | public void onCompleted(JSONObject object, GraphResponse response) {
|
128 |
| - try { |
129 |
| - String email = object.getString("email"); |
130 |
| - mCallbackObject.onSuccess(createIDPResponse(loginResult, email)); |
131 |
| - } catch (JSONException e) { |
132 |
| - e.printStackTrace(); |
| 129 | + FacebookRequestError requestError = response.getError(); |
| 130 | + if(requestError != null) { |
| 131 | + Log.e(TAG, |
| 132 | + "Received Facebook error: " + requestError.getErrorMessage()); |
133 | 133 | mCallbackObject.onFailure(new Bundle());
|
| 134 | + return; |
| 135 | + } |
| 136 | + if (object == null) { |
| 137 | + Log.w(TAG, "Received null response from Facebook GraphRequest"); |
| 138 | + mCallbackObject.onFailure(new Bundle()); |
| 139 | + } else { |
| 140 | + try { |
| 141 | + String email = object.getString("email"); |
| 142 | + mCallbackObject.onSuccess(createIDPResponse(loginResult, email)); |
| 143 | + } catch (JSONException e) { |
| 144 | + Log.e(TAG, "JSON Exception reading from Facebook GraphRequest", e); |
| 145 | + mCallbackObject.onFailure(new Bundle()); |
| 146 | + } |
134 | 147 | }
|
135 | 148 | }
|
136 | 149 | });
|
|
0 commit comments