1
0
mirror of https://github.com/TwidereProject/Twidere-Android synced 2025-02-17 04:00:48 +01:00

implemented some api

This commit is contained in:
Mariotaku Lee 2015-05-07 23:40:59 +08:00
parent f6b65be95e
commit a7d314dcc2
17 changed files with 551 additions and 172 deletions

View File

@ -262,7 +262,7 @@ public class ParcelableMedia implements Parcelable {
if (card == null) return null;
if ("animated_gif".equals(card.getName())) {
final BindingValue player_stream_url = card.getBindingValue("player_stream_url");
if (player_stream_url == null || !BindingValue.TYPE_STRING.equals(player_stream_url.getType()))
if (!(player_stream_url instanceof StringValue))
return null;
final ParcelableMedia media = new ParcelableMedia();

View File

@ -805,14 +805,17 @@ public class ParcelableStatus implements Parcelable, Comparable<ParcelableStatus
}
public ParcelableBindingValue(BindingValue value) {
this.type = value.getType();
if (BindingValue.TYPE_IMAGE.equals(type)) {
if (value instanceof ImageValue) {
this.type = BindingValue.TYPE_IMAGE;
this.value = ((ImageValue) value).getUrl();
} else if (BindingValue.TYPE_STRING.equals(type)) {
} else if (value instanceof StringValue) {
this.type = BindingValue.TYPE_STRING;
this.value = ((StringValue) value).getValue();
} else if (BindingValue.TYPE_BOOLEAN.equals(type)) {
} else if (value instanceof BooleanValue) {
this.type = BindingValue.TYPE_BOOLEAN;
this.value = String.valueOf(((BooleanValue) value).getValue());
} else if (BindingValue.TYPE_USER.equals(type)) {
} else if (value instanceof UserValue) {
this.type = BindingValue.TYPE_USER;
this.value = String.valueOf(((UserValue) value).getUserId());
}
}

View File

@ -45,34 +45,34 @@ public class ParcelableUserList implements Parcelable, Comparable<ParcelableUser
};
@JsonField(name = "members_count")
public int members_count;
public long members_count;
@JsonField(name = "subscribers_count")
public int subscribers_count;
public long subscribers_count;
@JsonField(name = "account_id")
public long account_id;
public long account_id;
@JsonField(name = "id")
public long id;
public long id;
@JsonField(name = "user_id")
public long user_id;
public long user_id;
@JsonField(name = "position")
public long position;
public long position;
@JsonField(name = "is_public")
public boolean is_public;
public boolean is_public;
@JsonField(name = "is_following")
public boolean is_following;
public boolean is_following;
@JsonField(name = "description")
public String description;
public String description;
@JsonField(name = "name")
public String name;
public String name;
@JsonField(name = "user_screen_name")
public String user_screen_name;
public String user_screen_name;
@JsonField(name = "user_name")
public String user_name;
public String user_name;
@JsonField(name = "user_profile_image_url")
public String user_profile_image_url;
public String user_profile_image_url;
public ParcelableUserList() {
}
@ -89,8 +89,8 @@ public class ParcelableUserList implements Parcelable, Comparable<ParcelableUser
user_name = in.readString();
user_screen_name = in.readString();
user_profile_image_url = in.readString();
members_count = in.readInt();
subscribers_count = in.readInt();
members_count = in.readLong();
subscribers_count = in.readLong();
}
public ParcelableUserList(final UserList list, final long account_id) {
@ -107,7 +107,7 @@ public class ParcelableUserList implements Parcelable, Comparable<ParcelableUser
this.position = position;
this.account_id = account_id;
id = list.getId();
is_public = list.isPublic();
is_public = list.getMode() == UserList.Mode.PUBLIC;
this.is_following = is_following;
name = list.getName();
description = list.getDescription();
@ -174,8 +174,8 @@ public class ParcelableUserList implements Parcelable, Comparable<ParcelableUser
out.writeString(user_name);
out.writeString(user_screen_name);
out.writeString(user_profile_image_url);
out.writeInt(members_count);
out.writeInt(subscribers_count);
out.writeLong(members_count);
out.writeLong(subscribers_count);
}
}

View File

@ -44,9 +44,7 @@ import static org.mariotaku.twidere.util.HtmlEscapeHelper.toPlainText;
public class TwitterContentUtils {
public static String formatDirectMessageText(final DirectMessage message) {
if (message == null) return null;
final String text = message.getRawText();
if (text == null) return null;
final HtmlBuilder builder = new HtmlBuilder(text, false, true, true);
final HtmlBuilder builder = new HtmlBuilder(message.getText(), false, true, true);
TwitterContentUtils.parseEntities(builder, message);
return builder.build().replace("\n", "<br/>");
}

View File

@ -11,5 +11,5 @@ import java.lang.annotation.Target;
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface Form {
String[] value();
String[] value() default {};
}

View File

@ -29,6 +29,8 @@ import org.mariotaku.simplerestapi.http.ContentType;
import org.mariotaku.simplerestapi.http.RestResponse;
import org.mariotaku.simplerestapi.http.mime.TypedData;
import org.mariotaku.twidere.api.twitter.auth.OAuthToken;
import org.mariotaku.twidere.api.twitter.model.impl.CardEntityImpl;
import org.mariotaku.twidere.api.twitter.model.impl.DirectMessageImpl;
import org.mariotaku.twidere.api.twitter.model.impl.ErrorInfoImpl;
import org.mariotaku.twidere.api.twitter.model.impl.HashtagEntityImpl;
import org.mariotaku.twidere.api.twitter.model.impl.Indices;
@ -47,6 +49,7 @@ import org.mariotaku.twidere.api.twitter.model.impl.TwitterResponseImpl;
import org.mariotaku.twidere.api.twitter.model.impl.TypeConverterMapper;
import org.mariotaku.twidere.api.twitter.model.impl.UrlEntityImpl;
import org.mariotaku.twidere.api.twitter.model.impl.UserImpl;
import org.mariotaku.twidere.api.twitter.model.impl.UserListImpl;
import org.mariotaku.twidere.api.twitter.model.impl.UserMentionEntityImpl;
import org.mariotaku.twidere.api.twitter.model.impl.Wrapper;
@ -62,6 +65,8 @@ import java.text.ParseException;
import java.util.HashMap;
import java.util.Map;
import twitter4j.CardEntity;
import twitter4j.DirectMessage;
import twitter4j.ErrorInfo;
import twitter4j.GeoLocation;
import twitter4j.HashtagEntity;
@ -78,6 +83,7 @@ import twitter4j.TranslationResult;
import twitter4j.TwitterException;
import twitter4j.UrlEntity;
import twitter4j.User;
import twitter4j.UserList;
import twitter4j.UserMentionEntity;
/**
@ -90,6 +96,8 @@ public class TwitterConverter implements Converter {
static {
TypeConverterMapper.register(Status.class, StatusImpl.class);
TypeConverterMapper.register(User.class, UserImpl.class);
TypeConverterMapper.register(UserList.class, UserListImpl.class);
TypeConverterMapper.register(DirectMessage.class, DirectMessageImpl.class);
TypeConverterMapper.register(SavedSearch.class, SavedSearchImpl.class);
TypeConverterMapper.register(UrlEntity.class, UrlEntityImpl.class);
TypeConverterMapper.register(MediaEntity.class, MediaEntityImpl.class);
@ -100,6 +108,7 @@ public class TwitterConverter implements Converter {
TypeConverterMapper.register(MediaEntity.VideoInfo.Variant.class, MediaEntityImpl.VideoInfoImpl.VariantImpl.class);
TypeConverterMapper.register(UserMentionEntity.class, UserMentionEntityImpl.class);
TypeConverterMapper.register(HashtagEntity.class, HashtagEntityImpl.class);
TypeConverterMapper.register(CardEntity.class, CardEntityImpl.class);
TypeConverterMapper.register(Place.class, PlaceImpl.class);
TypeConverterMapper.register(Relationship.class, RelationshipImpl.class);
TypeConverterMapper.register(MediaUploadResponse.class, MediaUploadResponseImpl.class);
@ -114,6 +123,7 @@ public class TwitterConverter implements Converter {
registerWrapper(QueryResult.class, QueryResultWrapper.class);
registerWrapper(PageableResponseList.class, PageableResponseListWrapper.class);
registerWrapper(Relationship.class, RelationshipWrapper.class);
registerWrapper(CardEntity.BindingValue.class, CardEntityImpl.BindingValueWrapper.class);
// TypeConverterMapper.register(DirectMessage.class, DirectMessageImpl.class);
}

View File

@ -0,0 +1,188 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.twidere.api.twitter.model.impl;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import org.mariotaku.simplerestapi.http.RestResponse;
import java.util.Map;
import twitter4j.CardEntity;
import twitter4j.RateLimitStatus;
import twitter4j.User;
/**
* Created by mariotaku on 15/5/7.
*/
@JsonObject
public class CardEntityImpl implements CardEntity {
@JsonField(name = "name")
String name;
@JsonField(name = "url")
String url;
@JsonField(name = "binding_values")
Map<String, BindingValue> bindingValues;
@Override
public String getName() {
return name;
}
@Override
public String getUrl() {
return url;
}
@Override
public User[] getUsers() {
return new User[0];
}
@Override
public BindingValue getBindingValue(String key) {
return bindingValues.get(key);
}
@Override
public Map<String, BindingValue> getBindingValues() {
return bindingValues;
}
@JsonObject
static class ImageValueImpl implements ImageValue {
@JsonField(name = "width")
int width;
@JsonField(name = "height")
int height;
@JsonField(name = "url")
String url;
@Override
public int getWidth() {
return width;
}
@Override
public int getHeight() {
return height;
}
@Override
public String getUrl() {
return url;
}
}
static class BooleanValueImpl implements BooleanValue {
public BooleanValueImpl(boolean value) {
this.value = value;
}
private boolean value;
@Override
public boolean getValue() {
return value;
}
}
static class StringValueImpl implements StringValue {
private final String value;
public StringValueImpl(String value) {
this.value = value;
}
@Override
public String getValue() {
return value;
}
}
@JsonObject
static class UserValueImpl implements UserValue {
@JsonField(name = "id")
long userId;
@Override
public long getUserId() {
return userId;
}
}
@JsonObject
public static class BindingValueWrapper implements Wrapper<BindingValue> {
@JsonField(name = "type")
String type;
@JsonField(name = "boolean_value")
boolean booleanValue;
@JsonField(name = "string_value")
String stringValue;
@JsonField(name = "image_value")
ImageValueImpl imageValue;
@JsonField(name = "user_value")
UserValueImpl userValue;
@Override
public BindingValue getWrapped(Object extra) {
if (type == null) return null;
switch (type) {
case BindingValue.TYPE_BOOLEAN: {
return new BooleanValueImpl(booleanValue);
}
case BindingValue.TYPE_STRING: {
return new StringValueImpl(stringValue);
}
case BindingValue.TYPE_IMAGE: {
return imageValue;
}
case BindingValue.TYPE_USER: {
return userValue;
}
}
return null;
}
@Override
public void processResponseHeader(RestResponse resp) {
}
@Override
public int getAccessLevel() {
return 0;
}
@Override
public RateLimitStatus getRateLimitStatus() {
return null;
}
}
}

View File

@ -19,13 +19,109 @@
package org.mariotaku.twidere.api.twitter.model.impl;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import org.mariotaku.twidere.api.twitter.TwitterDateConverter;
import java.util.Date;
import twitter4j.DirectMessage;
import twitter4j.HashtagEntity;
import twitter4j.MediaEntity;
import twitter4j.UrlEntity;
import twitter4j.UserMentionEntity;
/**
* Created by mariotaku on 15/5/7.
*/
@JsonObject
public class DirectMessageImpl {
public class DirectMessageImpl extends TwitterResponseImpl implements DirectMessage {
@JsonField(name = "created_at", typeConverter = TwitterDateConverter.class)
Date createdAt;
@JsonField(name = "sender")
UserImpl sender;
@JsonField(name = "recipient")
UserImpl recipient;
@JsonField(name = "entities")
EntitiesImpl entities;
@JsonField(name = "text")
String text;
@JsonField(name = "id")
long id;
@Override
public long getId() {
return id;
}
@Override
public String getText() {
return text;
}
@Override
public HashtagEntity[] getHashtagEntities() {
if (entities == null) return null;
return entities.getHashtags();
}
@Override
public MediaEntity[] getMediaEntities() {
if (entities == null) return null;
return entities.getMedia();
}
@Override
public UrlEntity[] getUrlEntities() {
if (entities == null) return null;
return entities.getUrls();
}
@Override
public UserMentionEntity[] getUserMentionEntities() {
if (entities == null) return null;
return entities.getUserMentions();
}
@Override
public Date getCreatedAt() {
return createdAt;
}
@Override
public UserImpl getSender() {
return sender;
}
@Override
public long getSenderId() {
return sender.id;
}
@Override
public String getSenderScreenName() {
return sender.screenName;
}
@Override
public UserImpl getRecipient() {
return recipient;
}
@Override
public long getRecipientId() {
return recipient.id;
}
@Override
public String getRecipientScreenName() {
return recipient.screenName;
}
}

View File

@ -0,0 +1,158 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.twidere.api.twitter.model.impl;
import android.support.annotation.NonNull;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import org.mariotaku.twidere.api.twitter.TwitterDateConverter;
import java.util.Date;
import twitter4j.User;
import twitter4j.UserList;
/**
* Created by mariotaku on 15/4/7.
*/
@JsonObject
public class UserListImpl extends TwitterResponseImpl implements UserList {
@JsonField(name = "id")
long id;
@JsonField(name = "name")
String name;
@JsonField(name = "uri")
String uri;
@JsonField(name = "subscriber_count")
long subscriberCount;
@JsonField(name = "member_count")
long memberCount;
@JsonField(name = "mode")
Mode mode;
@JsonField(name = "description")
String description;
@JsonField(name = "slug")
String slug;
@JsonField(name = "full_name")
String fullName;
@JsonField(name = "created_at", typeConverter = TwitterDateConverter.class)
Date createdAt;
@JsonField(name = "following")
boolean following;
@JsonField(name = "user")
User user;
@Override
public long getId() {
return id;
}
@Override
public String getName() {
return name;
}
public String getUri() {
return uri;
}
@Override
public long getSubscriberCount() {
return subscriberCount;
}
@Override
public long getMemberCount() {
return memberCount;
}
@Override
public Mode getMode() {
return mode;
}
@Override
public String getDescription() {
return description;
}
@Override
public String getSlug() {
return slug;
}
@Override
public String getFullName() {
return fullName;
}
@Override
public Date getCreatedAt() {
return createdAt;
}
@Override
public boolean isFollowing() {
return following;
}
@Override
public User getUser() {
return user;
}
@Override
public int compareTo(@NonNull UserList another) {
return (int) (id - another.getId());
}
@Override
public String toString() {
return "UserListImpl{" +
"id=" + id +
", name='" + name + '\'' +
", uri='" + uri + '\'' +
", subscriberCount=" + subscriberCount +
", memberCount=" + memberCount +
", mode=" + mode +
", description='" + description + '\'' +
", slug='" + slug + '\'' +
", fullName='" + fullName + '\'' +
", createdAt=" + createdAt +
", following=" + following +
", user=" + user +
"} " + super.toString();
}
}

View File

@ -20,6 +20,7 @@
package twitter4j;
import java.io.Serializable;
import java.util.Map;
/**
* Created by mariotaku on 14/12/31.
@ -34,7 +35,7 @@ public interface CardEntity extends Serializable {
BindingValue getBindingValue(String key);
java.util.Map<String, BindingValue> getBindingValues();
Map<String, BindingValue> getBindingValues();
interface BindingValue extends Serializable {
@ -43,9 +44,6 @@ public interface CardEntity extends Serializable {
String TYPE_USER = "USER";
String TYPE_BOOLEAN = "BOOLEAN";
String getName();
String getType();
}

View File

@ -33,8 +33,6 @@ public interface DirectMessage extends TwitterResponse, EntitySupport {
long getId();
String getRawText();
User getRecipient();
long getRecipientId();

View File

@ -148,8 +148,6 @@ public final class TwitterFactory {
} else {
sslSocketFactory = (SSLCertificateSocketFactory) SSLCertificateSocketFactory.getDefault(0, null);
}
// sslSocketFactory.setTrustManagers(new TrustManager[]{new TwidereTrustManager(context)});
// client.setHostnameVerifier(new HostResolvedHostnameVerifier(context, ignoreSSLError));
client.setSslSocketFactory(sslSocketFactory);
client.setSocketFactory(SocketFactory.getDefault());
client.setConnectTimeout(conf.getHttpConnectionTimeout(), TimeUnit.MILLISECONDS);

View File

@ -17,88 +17,54 @@
package twitter4j;
import java.io.Serializable;
import java.net.URI;
import java.util.Date;
/**
* A data interface representing Basic list information element
*
* @author Dan Checkoway - dcheckoway at gmail.com
*/
public interface UserList extends Comparable<UserList>, TwitterResponse, Serializable {
/**
* Returns the description of the list
*
* @return the description of the list
*/
String getDescription();
Mode getMode();
/**
* Returns the full name of the list
*
* @return the full name of the list
*/
String getFullName();
String getDescription();
/**
* Returns the id of the list
*
* @return the id of the list
*/
long getId();
/**
* Returns the member count of the list
*
* @return the member count of the list
*/
int getMemberCount();
String getFullName();
/**
* Returns the name of the list
*
* @return the name of the list
*/
String getName();
/**
* Returns the slug of the list
*
* @return the slug of the list
*/
String getSlug();
long getId();
/**
* Returns the subscriber count of the list
*
* @return the subscriber count of the list
*/
int getSubscriberCount();
/**
* Returns the uri of the list
*
* @return the uri of the list
*/
URI getURI();
long getMemberCount();
/**
* Returns the user of the list
*
* @return the user of the list
*/
User getUser();
/**
* Returns if the authenticated user is following the list
*
* @return if the authenticated user is following the list
*/
boolean isFollowing();
String getName();
/**
* tests if the list is public
*
* @return if the list is public
*/
boolean isPublic();
String getSlug();
long getSubscriberCount();
String getUri();
User getUser();
Date getCreatedAt();
boolean isFollowing();
enum Mode {
PUBLIC, PRIVATE;
public static Mode parse(String str) {
switch (str) {
case "public":
return PUBLIC;
case "private":
return PRIVATE;
}
throw new UnsupportedOperationException();
}
}
}

View File

@ -41,13 +41,13 @@ public interface DirectMessagesResources {
ResponseList<DirectMessage> getDirectMessages() throws TwitterException;
@GET("/direct_messages.json")
ResponseList<DirectMessage> getDirectMessages(@Query({"since_id", "max_id", "count"}) Paging paging) throws TwitterException;
ResponseList<DirectMessage> getDirectMessages(@Query Paging paging) throws TwitterException;
@GET("/direct_messages/sent.json")
ResponseList<DirectMessage> getSentDirectMessages() throws TwitterException;
@GET("/direct_messages/sent.json")
ResponseList<DirectMessage> getSentDirectMessages(@Query({"since_id", "max_id", "count"}) Paging paging) throws TwitterException;
ResponseList<DirectMessage> getSentDirectMessages(@Query Paging paging) throws TwitterException;
@POST("/direct_messages/new.json")
@Body(BodyType.FORM)
@ -65,5 +65,6 @@ public interface DirectMessagesResources {
@Body(BodyType.FORM)
DirectMessage sendDirectMessage(@Form("screen_name") String screenName, @Form("text") String text, @Form("media_id") long mediaId) throws TwitterException;
DirectMessage showDirectMessage(long id) throws TwitterException;
@GET("/direct_messages/show.json")
DirectMessage showDirectMessage(@Query("id") long id) throws TwitterException;
}

View File

@ -19,7 +19,11 @@
package twitter4j.api;
import org.mariotaku.simplerestapi.http.BodyType;
import org.mariotaku.simplerestapi.method.GET;
import org.mariotaku.simplerestapi.method.POST;
import org.mariotaku.simplerestapi.param.Body;
import org.mariotaku.simplerestapi.param.Form;
import org.mariotaku.simplerestapi.param.Query;
import twitter4j.Paging;
@ -31,34 +35,14 @@ import twitter4j.TwitterException;
* @author Joern Huxhorn - jhuxhorn at googlemail.com
*/
public interface FavoritesResources {
/**
* Favorites the status specified in the ID parameter as the authenticating
* user. Returns the favorite status when successful. <br>
* This method calls http://api.twitter.com/1.1/favorites/create/[id].json
*
* @param id the ID of the status to favorite
* @return Status
* @throws twitter4j.TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/post/favorites/create/:id">POST
* favorites/create/:id | Twitter Developers</a>
*/
Status createFavorite(long id) throws TwitterException;
/**
* Un-favorites the status specified in the ID parameter as the
* authenticating user. Returns the un-favorited status in the requested
* format when successful. <br>
* This method calls http://api.twitter.com/1.1/favorites/destroy/[id].json
*
* @param id the ID of the status to un-favorite
* @return Status
* @throws twitter4j.TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/post/favorites/destroy/:id">POST
* favorites/destroy/:id | Twitter Developers</a>
*/
Status destroyFavorite(long id) throws TwitterException;
@POST("/favorites/create.json")
@Body(BodyType.FORM)
Status createFavorite(@Form("id") long id) throws TwitterException;
@POST("/favorites/destroy.json")
@Body(BodyType.FORM)
Status destroyFavorite(@Form("id") long id) throws TwitterException;
@GET("/favorites/list.json")
ResponseList<Status> getFavorites() throws TwitterException;

View File

@ -42,38 +42,14 @@ public interface TweetResources {
@POST("/statuses/destroy/{id}.json")
Status destroyStatus(@Path("id") long statusId) throws TwitterException;
IDs getRetweetersIDs(long statusId) throws TwitterException;
@GET("/statuses/retweeters/ids.json")
IDs getRetweetersIDs(@Query("id") long statusId) throws TwitterException;
IDs getRetweetersIDs(long statusId, Paging paging) throws TwitterException;
@GET("/statuses/retweeters/ids.json")
IDs getRetweetersIDs(@Query("id") long statusId, @Query Paging paging) throws TwitterException;
/**
* Returns up to 100 of the first retweets of a given tweet. <br>
* This method calls http://api.twitter.com/1.1/statuses/retweets
*
* @param statusId The numerical ID of the tweet you want the retweets of.
* @return the retweets of a given tweet
* @throws twitter4j.TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/get/statuses/retweets/:id">Tweets
* Resources statuses/retweets/:id</a>
* @since Twitter4J 2.0.10
*/
ResponseList<Status> getRetweets(long statusId) throws TwitterException;
/**
* Returns up to 100 of the first retweets of a given tweet. <br>
* This method calls http://api.twitter.com/1.1/statuses/retweets
*
* @param statusId The numerical ID of the desired status.
* @param count Specifies the number of records to retrieve. Must be less
* than or equal to 100.
* @return the retweets of a given tweet
* @throws twitter4j.TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/get/statuses/retweets/:id">Tweets
* Resources statuses/retweets/:id</a>
* @since Twitter4J 2.0.10
*/
ResponseList<Status> getRetweets(long statusId, int count) throws TwitterException;
int reportSpam(long statusId, ReportAs reportAs, boolean blockUser) throws TwitterException;
@ -86,8 +62,7 @@ public interface TweetResources {
@POST("/statuses/update.json")
@Body(BodyType.FORM)
Status updateStatus(@Form({"status", "in_reply_to_status_id", "possibly_sensitive", "lat",
"long", "place_id", "display_coordinates", "media_ids"}) StatusUpdate latestStatus) throws TwitterException;
Status updateStatus(@Form StatusUpdate latestStatus) throws TwitterException;
@POST("/statuses/update.json")
@Body(BodyType.FORM)

View File

@ -33,6 +33,7 @@ import java.util.List;
import twitter4j.Twitter;
import twitter4j.TwitterConstants;
import twitter4j.TwitterFactory;
import twitter4j.conf.Configuration;
import twitter4j.conf.ConfigurationBuilder;
import twitter4j.http.HostAddressResolverFactory;
@ -91,6 +92,13 @@ public class TwitterAPIUtils {
final boolean includeEntities,
final boolean includeRetweets, Class<T> cls) {
if (context == null) return null;
final ParcelableAccount.ParcelableCredentials credentials = ParcelableAccount.ParcelableCredentials.getCredentials(context, accountId);
if (credentials == null) return null;
final Configuration conf = getConfiguration(context, includeEntities, includeRetweets, credentials);
return new TwitterFactory(conf).getInstance(getAuthorization(credentials), cls);
}
private static Configuration getConfiguration(Context context, boolean includeEntities, boolean includeRetweets, ParcelableAccount.ParcelableCredentials credentials) {
final TwidereApplication app = TwidereApplication.getInstance(context);
final SharedPreferences prefs = context.getSharedPreferences(TwidereConstants.SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
final int connection_timeout = prefs.getInt(SharedPreferenceConstants.KEY_CONNECTION_TIMEOUT, 10) * 1000;
@ -99,8 +107,6 @@ public class TwitterAPIUtils {
final boolean enableProxy = prefs.getBoolean(SharedPreferenceConstants.KEY_ENABLE_PROXY, false);
// Here I use old consumer key/secret because it's default key for older
// versions
final ParcelableAccount.ParcelableCredentials credentials = ParcelableAccount.ParcelableCredentials.getCredentials(context, accountId);
if (credentials == null) return null;
final ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setHostAddressResolverFactory(new TwidereHostResolverFactory(app));
cb.setHttpConnectionTimeout(connection_timeout);
@ -140,7 +146,7 @@ public class TwitterAPIUtils {
cb.setIncludeRTsEnabled(includeRetweets);
cb.setIncludeReplyCountEnabled(true);
cb.setIncludeDescendentReplyCountEnabled(true);
return new TwitterFactory(cb.build()).getInstance(getAuthorization(credentials), cls);
return cb.build();
}
public static Authorization getAuthorization(ParcelableAccount.ParcelableCredentials credentials) {