33import android .util .Log ;
44import java .util .HashMap ;
55import java .util .Random ;
6+ import java .util .List ;
67import android .support .annotation .Nullable ;
78import java .net .URL ;
89import java .net .MalformedURLException ;
10+ import android .text .TextUtils ;
11+ import java .util .Arrays ;
912
1013import com .github .scribejava .core .model .Verb ;
1114import com .github .scribejava .core .builder .api .BaseApi ;
@@ -156,7 +159,9 @@ private static OAuth10aService twitterService(
156159
157160 String scopes = (String ) cfg .get ("scopes" );
158161 if (scopes != null ) {
159- builder .scope (scopes );
162+ // String scopeStr = OAuthManagerProviders.getScopeString(scopes, "+");
163+ // Log.d(TAG, "scopeStr: " + scopeStr);
164+ // builder.scope(scopeStr);
160165 }
161166
162167 if (callbackUrl != null ) {
@@ -228,10 +233,14 @@ private static ServiceBuilder _oauth2ServiceBuilder(
228233 String scopes = "" ;
229234 if (cfg .containsKey ("scopes" )) {
230235 scopes = (String ) cfg .get ("scopes" );
231- builder .scope (scopes );
232- } else if (opts != null && opts .hasKey ("scopes" )) {
236+ String scopeStr = OAuthManagerProviders .getScopeString (scopes , "," );
237+ builder .scope (scopeStr );
238+ }
239+
240+ if (opts != null && opts .hasKey ("scopes" )) {
233241 scopes = (String ) opts .getString ("scopes" );
234- builder .scope (scopes );
242+ String scopeStr = OAuthManagerProviders .getScopeString (scopes , "," );
243+ builder .scope (scopeStr );
235244 }
236245
237246 if (callbackUrl != null ) {
@@ -240,4 +249,16 @@ private static ServiceBuilder _oauth2ServiceBuilder(
240249
241250 return builder ;
242251 }
252+
253+ /**
254+ * Convert a list of scopes by space or string into an array
255+ */
256+ private static String getScopeString (
257+ final String scopes ,
258+ final String joinBy
259+ ) {
260+ List <String > array = Arrays .asList (scopes .replaceAll ("\\ s" , "" ).split ("[ ,]+" ));
261+ Log .d (TAG , "array: " + array + " (" + array .size () + ") from " + scopes );
262+ return TextUtils .join (joinBy , array );
263+ }
243264}
0 commit comments