Skip to content

Instantly share code, notes, and snippets.

@jasonpolites
Created August 8, 2011 22:58
Show Gist options
  • Save jasonpolites/1132969 to your computer and use it in GitHub Desktop.
Save jasonpolites/1132969 to your computer and use it in GitHub Desktop.
Socialize SDK Android - Likes
import com.socialize.Socialize;
import com.socialize.entity.Like;
import com.socialize.error.SocializeException;
import com.socialize.listener.like.LikeAddListener;
if(Socialize.getSocialize().isAuthenticated()) {
// Add a like to an entity defined by its URL
Socialize.getSocialize().like("http://someurl.com", new LikeAddListener() {
public void onError(SocializeException error) {
// Handle error
}
public void onCreate(Like like) {
// Handle success
}
});
}
if(Socialize.getSocialize().isAuthenticated(AuthProviderType.FACEBOOK)) {
// Call the like function
doLike("http://someurl.com");
}
else {
Socialize.getSocialize().authenticate(
consumerKey, // From your account at getsocialize.com
consumerSecret, // From your account at getsocialize.com
AuthProviderType.FACEBOOK,
facebookAppId, // Your facebook app ID
new SocializeAuthListener() {
public void onAuthSuccess(SocializeSession session) {
// Success!
doLike("http://someurl.com");
}
public void onAuthFail(SocializeException error) {
// Handle auth fail
}
public void onError(SocializeException error) {
// Handle error
}
});
}
//...
public void doLike(String url) {
// Add a like to an entity defined by its URL
Socialize.getSocialize().like(url, new LikeAddListener() {
public void onError(SocializeException error) {
// Handle error
}
public void onCreate(Like like) {
// Handle success
}
});
}
import com.socialize.Socialize;
import com.socialize.entity.Like;
import com.socialize.error.SocializeException;
import com.socialize.listener.like.LikeGetListener;
if(Socialize.getSocialize().isAuthenticated()) {
// Get an existing like for an entity
Socialize.getSocialize().getLike("http://someurl.com", new LikeGetListener() {
public void onError(SocializeException error) {
// Handle error
}
public void onGet(Like like) {
// Handle success
}
});
}
import com.socialize.Socialize;
import com.socialize.entity.Like;
import com.socialize.entity.ListResult;
import com.socialize.error.SocializeException;
import com.socialize.listener.like.LikeListListener;
if(Socialize.getSocialize().isAuthenticated()) {
// List likes for a single user
Socialize.getSocialize().listLikesByUser(1234, new LikeListListener() {
public void onError(SocializeException error) {
// Handle error
}
public void onList(ListResult<Like> likes) {
// Handle success
}
});
}
import com.socialize.Socialize;
import com.socialize.entity.ListResult;
import com.socialize.entity.SocializeAction;
import com.socialize.error.SocializeException;
import com.socialize.listener.activity.UserActivityListListener;
if(Socialize.getSocialize().isAuthenticated()) {
// You can provide any user id you like, but here's how to use the current logged in user
Long userId = Socialize.getSocialize().getSession().getUser().getId();
// List all activity for a single user
Socialize.getSocialize().listActivityByUser(userId, new UserActivityListListener() {
public void onError(SocializeException error) {
// Handle error
}
public void onList(ListResult<SocializeAction> activity) {
// Handle success
}
});
}
import com.socialize.Socialize;
import com.socialize.entity.ListResult;
import com.socialize.entity.SocializeAction;
import com.socialize.error.SocializeException;
import com.socialize.listener.activity.UserActivityListListener;
if(Socialize.getSocialize().isAuthenticated()) {
// You can provide any user id you like, but here's how to use the current logged in user
Long userId = Socialize.getSocialize().getSession().getUser().getId();
// Set the start/end index for pagination
int startIndex = 0;
int endIndex = 10;
// List all activity for a single user
Socialize.getSocialize().listActivityByUser(
userId,
startIndex,
endIndex,
new UserActivityListListener() {
public void onError(SocializeException error) {
// Handle error
}
public void onList(ListResult<SocializeAction> activity) {
// Handle success
}
});
}
import com.socialize.Socialize;
import com.socialize.entity.Comment;
import com.socialize.entity.ListResult;
import com.socialize.error.SocializeException;
import com.socialize.listener.comment.CommentListListener;
if(Socialize.getSocialize().isAuthenticated()) {
// List comments for a single user
Socialize.getSocialize().listCommentsByUser(1234, new CommentListListener() {
public void onError(SocializeException error) {
// Handle error
}
public void onList(ListResult<Comment> likes) {
// Handle success
}
});
}
import com.socialize.Socialize;
import com.socialize.entity.Like;
import com.socialize.error.SocializeException;
import com.socialize.listener.like.LikeDeleteListener;
if(Socialize.getSocialize().isAuthenticated()) {
// Remove an existing like based on its numeric ID
Socialize.getSocialize().unlike(1234, new LikeDeleteListener() {
public void onError(SocializeException error) {
// Handle error
}
public void onDelete() {
// Handle success
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment