This library implements the Disqus API for use in Android applications. The library is currently incomplete and under development so is subject to change.
Add the following to your build.gradle:
compile 'me.philio.disqus:disqus:0.0.11'
-
Use
AuthorizeUtils.createIntentto create a newIntentwith 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) { if (resultCode == RESULT_OK) { // Auth completed, get the access token AccessToken accessToken = data.getParcelableExtra(AuthorizeActivity.EXTRA_ACCESS_TOKEN); } else { // Auth failed } super.onActivityResult(requestCode, resultCode, data); }
-
Add the fragment to your activity via
AuthorizeFragment.newInstance. -
Your activity should implement the
AuthorizeFragment.AuthorizeListenercallback. -
You may need to handle failures/cancellations within your activity, e.g. if back is pressed as currently the cancel button on the Disqus auth page doesn't seem to work.
Third party logins are not supported at this time.
Use the ApiConfig class to set your app configuration
ApiConfig apiConfig = new ApiConfig("MyApiKey", "AccessToken", LogLevel.BASIC);
- 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.0.5 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.
In general:
-
Named parameters are required and should not be null.
-
Optional parameters can be provided as a
Mapwhere 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.