/** {@inheritDoc} */ @Override public void configure(Map<String, String> providerParams) { autoLogin = false; if (providerParams != null) { twitterConsumerKey = providerParams.get("consumerKey"); twitterConsumerSecret = providerParams.get("consumerSecret"); // extract autoLogin String autoLoginStr = providerParams.get("autoLogin"); autoLogin = autoLoginStr != null && Boolean.parseBoolean(autoLoginStr); } SoomlaUtils.LogDebug( TAG, String.format( "ConsumerKey:%s ConsumerSecret:%s", twitterConsumerKey, twitterConsumerSecret)); if (TextUtils.isEmpty(twitterConsumerKey) || TextUtils.isEmpty(twitterConsumerSecret)) { SoomlaUtils.LogError( TAG, "You must provide the Consumer Key and Secret in the SoomlaProfile initialization parameters"); isInitialized = false; } else { isInitialized = true; } oauthCallbackURL = "oauth://soomla_twitter" + twitterConsumerKey; ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setOAuthConsumerKey(twitterConsumerKey); configurationBuilder.setOAuthConsumerSecret(twitterConsumerSecret); Configuration configuration = configurationBuilder.build(); twitter = new AsyncTwitterFactory(configuration).getInstance(); if (!actionsListenerAdded) { SoomlaUtils.LogWarning(TAG, "added action listener"); twitter.addListener(actionsListener); actionsListenerAdded = true; } }
public void testSchema() throws Exception { String[] schema; String url; // JSONObject json = new // JSONObject("{\"a\":\"avalue\",\"b\":\"bvalue\",\"c\":{\"c-1\":12,\"c-2\":\"c-2value\"}}"); // schema = new String[]{"a", "b", "c/c-1", "c/c-2"}; // validateJSONObjectSchema(json, schema); // try { // schema = new String[]{"a", "b", "c/c-1"}; // validateJSONObjectSchema(json, schema); // fail("c/c-2 is missing. expecting an AssertionFailedError."); // } catch (AssertionFailedError ignore) { //// ignore.printStackTrace(); // } // try { // schema = new String[]{"a", "b"}; // validateJSONObjectSchema(json, schema); // fail("c is missing. expecting an AssertionFailedError."); // } catch (AssertionFailedError ignore) { //// ignore.printStackTrace(); // } // try { // schema = new String[]{"a", "b","c"}; // validateJSONObjectSchema(json, schema); // fail("c/* is missing. expecting an AssertionFailedError."); // } catch (AssertionFailedError ignore) { //// ignore.printStackTrace(); // } // schema = new String[]{"a", "b", "c/*"}; // validateJSONObjectSchema(json, schema); // // JSONArray array = new JSONArray("[{\"slug\":\"art-design\",\"name\":\"Art & // Design\"},{\"slug\":\"books\",\"name\":\"Books\"}]"); // schema = new String[]{"slug", "name"}; // validateJSONArraySchema(array, schema); // Location // schema = new // String[]{"url","country","woeid","placeType/name","placeType/code","name","countryCode"}; // url = "http://api.twitter.com/1.1/trends/available.json"; // validateJSONArraySchema(url, schema); // Place if (!Boolean.valueOf(System.getProperties().getProperty("twitter4j.test.schema"))) { // skipping schema validation return; } schema = new String[] { "slug", "name", "size", }; url = "http://api.twitter.com/1.1/users/suggestions.json"; List categories = CategoryJSONImpl.createCategoriesList(validateJSONArraySchema(url, schema), null, conf); Assert.assertEquals(20, categories.size()); schema = new String[] {"slug", "name", "size", "categories/*", "users/*"}; url = "http://api.twitter.com/1.1/users/suggestions/art-design.json"; validateJSONObjectSchema(url, schema); schema = new String[] { "result/places/name", "result/places/street_address", "result/places/attributes/*", "result/places/country_code", "result/places/id", "result/places/country", "result/places/place_type", "result/places/url", "result/places/full_name", "result/places/bounding_box/*", "result/places/contained_within/place_type", "result/places/contained_within/attributes/*", "result/places/contained_within/street_address", "result/places/contained_within/url", "result/places/contained_within/bounding_box/type", "result/places/contained_within/bounding_box/coordinates/*", "result/places/contained_within/full_name", "result/places/contained_within/country_code", "result/places/contained_within/name", "result/places/contained_within/id", "result/places/contained_within/country", "query", "query/type", "query/url", "query/params", "query/params/granularity", "query/params/coordinates", "query/params/coordinates/type", "query/params/coordinates/coordinates", "query/params/coordinates/coordinates/*", "query/params/accuracy", }; url = "http://api.twitter.com/1.1/geo/reverse_geocode.json?lat=37.78215&long=-122.40060"; validateJSONObjectSchema(url, schema); schema = new String[] { "next_cursor", "next_cursor_str", "previous_cursor", "previous_cursor_str", "lists/id", "lists/id_str", "lists/member_count", "lists/description", "lists/name", "lists/subscriber_count", "lists/slug", "lists/user/*", "lists/uri", "lists/full_name", "lists/mode", "lists/following", }; url = "http://api.twitter.com/1.1/twit4j2/lists.json"; validateJSONObjectSchema(url, schema); schema = new String[] { "id", "id_str", "member_count", "description", "name", "subscriber_count", "slug", "user/*", "uri", "full_name", "mode", "following", }; url = "http://api.twitter.com/1.1/twit4j2/lists/9499823.json"; UserList userList = new UserListJSONImpl(validateJSONObjectSchema(url, schema)); Assert.assertEquals("", userList.getDescription()); Assert.assertEquals("@twit4j2/test", userList.getFullName()); Assert.assertEquals(9499823, userList.getId()); Assert.assertTrue(1 < userList.getMemberCount()); Assert.assertEquals("test", userList.getName()); Assert.assertEquals("test", userList.getSlug()); Assert.assertEquals(0, userList.getSubscriberCount()); Assert.assertEquals("/twit4j2/test", userList.getURI().toString()); Assert.assertNotNull(userList.getUser()); Assert.assertTrue(userList.isPublic()); Assert.assertFalse(userList.isFollowing()); schema = new String[] { "favorited", "in_reply_to_status_id", "in_reply_to_status_id_str", "created_at", "geo", "place", "source", "in_reply_to_screen_name", "in_reply_to_user_id", "in_reply_to_user_id_str", "coordinates", "truncated", "contributors", "id", "id_str", "text", "user/*", "retweeted", "retweet_count" }; url = "http://api.twitter.com/1.1/statuses/show/2245071380.json"; Status status = new StatusJSONImpl(validateJSONObjectSchema(url, schema)); schema = new String[] { "profile_background_image_url", "created_at", "friends_count", "profile_link_color", "description", "contributors_enabled", "status/*", "following", "profile_background_tile", "favourites_count", "profile_sidebar_fill_color", "url", "profile_image_url", "geo_enabled", "notifications", "profile_sidebar_border_color", "location", "screen_name", "verified", "time_zone", "profile_background_color", "profile_use_background_image", "protected", "name", "profile_text_color", "followers_count", "id", "id_str", "lang", "statuses_count", "follow_request_sent", "utc_offset", "listed_count", "is_translator", "show_all_inline_media" }; url = "http://api.twitter.com/1.1/users/show/yusukey.json"; User user = new UserJSONImpl(validateJSONObjectSchema(url, schema)); }