Created
August 8, 2011 22:58
-
-
Save jasonpolites/1132969 to your computer and use it in GitHub Desktop.
Socialize SDK Android - Likes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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