This is the simple library for https://disqus.com/ developed on Android.
This library implements the Disqus API for use in Android applications. This librar is ongoing
repositories {
maven { url 'https://dl.bintray.com/jjhesk/maven' }
}
dependencies {
compile 'DisqusSDK-Android:disqus:0.2.7'
}
- Post comments
- Post Comments more flexible
- Updated authentication OAuth2.0 standard
- Additional support for the CacheUrl mechanism
- enable extending from fragment. PostCommentFragment
- setup the activity for login
- construct the configuration object
- enable extending from fragment. PostCommentFragment
- setup the activity for login
- construct the configuration object
- Use
AuthorizeUtils.createIntent
to create a newIntent
with your application settings. - Start the activity with
startActivityForResult
. - Implement 'onActivityResult' to get the access token object:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Check which request we're responding to
if (requestCode == DisqusClient.authorization_intent_id) {
// Make sure the request was successful
if (resultCode == RESULT_CANCELED) {
Toast.makeText(this, getResources().getString(com.hkm.disqus.R.string.failurelogin), Toast.LENGTH_LONG);
}
if (resultCode == RESULT_OK) {
AccessToken token = (AccessToken) data.getExtras().getParcelable(AuthorizeActivity.EXTRA_ACCESS_TOKEN);
addLine(token.accessToken);
release_pending_content();
}
}
}
protect void release_pending_content(){
if (appending_post_content != null) {
postPost(appending_post_content, post_post_id);
appending_post_content = null;
}
}
- ApiConfiguration Object Sample:
The
forum name
will be used as the following reference:
public class DqUtil {
public static ApiConfig genConfig() {
ApiConfig conf = new ApiConfig(
BuildConfig.DISQUS_API_KEY,
BuildConfig.DISQUS_DEFAULT_ACCESS,
RestAdapter.LogLevel.BASIC);
conf
.setForumName("__forum_name__")
.setApiSecret(BuildConfig.DISQUS_SECRET)
.setRedirectUri(BuildConfig.DISQUS_REDIRECT_URI);
return conf;
}
}
- API key - mandatory for all requests.
- Access token - required for requests that require authentication.
- Referrer - required for some requests that perform domain checks, should match a domain in your Disqus app settings.
- Log level - set the Retrofit logging level, see Square's docs for details.
- API secret - intended for server to server requests as an alternative to the API key/access token and provided for completeness. Can be used from a mobile app but this presents security risks and is not recommended.
As of version 0.9.0 the library is using Retrofit for requests.
The ApiClient
can be used to create Disqus resource objects based on the Retrofit interfaces
defined in the me.philio.disqus.api.resources
package. It works as a wrapper to the Retrofit
RestAdapter
and configures the adapter and deserialisation options for Gson.
ApiClient apiClient = new ApiClient(apiConfig);
Applications applications = apiClient.createApplications();
Response<Usage> usage = applications.listUsage("MyApp", 7);
All resources and requests match the naming conventions defined in the Disqus API documentation, but often method signatures are kept as simple as possible.
setup.createThreads().listPostByIDAsync(comment_id, "hypebeast", cb);
private void getPost() {
try {
base.getComments("1008680 http://hypebeast.com/?p=1008680", new Callback<com.hkm.disqus.api.model.Response<List<Post>>>() {
@Override
public void success(com.hkm.disqus.api.model.Response<List<Post>> posts, Response response) {
com.hkm.disqus.api.model.Response<List<Post>> d = posts;
Log.d(TAG, "now its working now");
}
@Override
public void failure(RetrofitError error) {
Log.d(TAG, error.getMessage());
}
});
} catch (ApiException e) {
}
}
In general:
-
Named parameters are required and should not be null.
-
Optional parameters can be provided as a
Map
where applicable, refer to the Disqus documentation for details of optional parameters.
All requests will return a Response
object. Typical responses contain an error code (which will
always be 0 as errors throw exceptions), an optional cursor (which can be used for pagination) and
some data which is a generic type.
The data is usually an object or list of objects and for the majority of requests will be one of the
models defined in the API package. Some requests return empty structures so to avoid parsing issues
the data type is either Object
or List<Object>
, the response data for these requests can be
disregarded.
- The cancel button for the authorisation page doesn't work.
- Related param has no effect when used with
Blacklists.list()
method. - update after post thread doesnt work.