A sample implementation of asynchronous API requests. This class provides the ability to execute API methods and have the call return immediately, without blocking the calling thread. This is necessary when accessing the API in the UI thread, for instance. The request response is returned to the caller via a callback interface, which the developer must implement.
This sample implementation simply spawns a new thread for each request, and makes the API call immediately. This may work in many applications, but more sophisticated users may re-implement this behavior using a thread pool, a network thread, a request queue, or other mechanism. Advanced functionality could be built, such as rate-limiting of requests, as per a specific application's needs.
ขยาย: | Object |
แพ็คเกจ: | android |
AsyncFacebookRunner(Facebook)
public AsyncFacebookRunner(Facebook fb)
พารามิเตอร์ | คำอธิบาย |
---|---|
fb |
logout(Context, RequestListener, Object)
Invalidate the current user session by removing the access token in memory, clearing the browser cookies, and calling auth.expireSession through the API. The application will be notified when logout is complete via the callback interface.
Note that this method is asynchronous and the callback will be invoked in a background thread; operations that affect the UI will need to be posted to the UI thread or an appropriate handler.
This method is deprecated. See Facebook and Session for more info.
public void logout(Context context, RequestListener listener, Object state)
พารามิเตอร์ | คำอธิบาย |
---|---|
context | The Android context in which the logout should be called: it should be the same context in which the login occurred in order to clear any stored cookies |
listener | Callback interface to notify the application when the request has completed. |
state | An arbitrary object used to identify the request when it returns to the callback. This has no effect on the request itself. |
logout(Context, RequestListener)
public void logout(Context context, RequestListener listener)
พารามิเตอร์ | คำอธิบาย |
---|---|
context | |
listener |
request(Bundle, RequestListener, Object)
Make a request to Facebook's old (pre-graph) API with the given parameters. One of the parameter keys must be "method" and its value should be a valid REST server API method.
See http://developers.facebook.com/docs/reference/rest/
Note that this method is asynchronous and the callback will be invoked in a background thread; operations that affect the UI will need to be posted to the UI thread or an appropriate handler.
Example:
Bundle parameters = new Bundle(); parameters.putString("method", "auth.expireSession", new Listener()); String response = request(parameters);
This method is deprecated. See Facebook and Request for more info.
public void request(Bundle parameters, RequestListener listener, Object state)
พารามิเตอร์ | คำอธิบาย |
---|---|
parameters | Key-value pairs of parameters to the request. Refer to the documentation: one of the parameters must be "method". |
listener | Callback interface to notify the application when the request has completed. |
state | An arbitrary object used to identify the request when it returns to the callback. This has no effect on the request itself. |
request(Bundle, RequestListener)
public void request(Bundle parameters, RequestListener listener)
พารามิเตอร์ | คำอธิบาย |
---|---|
parameters | |
listener |
request(String, RequestListener, Object)
Make a request to the Facebook Graph API without any parameters.
See http://developers.facebook.com/docs/api
Note that this method is asynchronous and the callback will be invoked in a background thread; operations that affect the UI will need to be posted to the UI thread or an appropriate handler.
This method is deprecated. See Facebook and Request for more info.
public void request(String graphPath, RequestListener listener, Object state)
พารามิเตอร์ | คำอธิบาย |
---|---|
graphPath | Path to resource in the Facebook graph, e.g., to fetch data about the currently logged authenticated user, provide "me", which will fetch http://graph.facebook.com/me |
listener | Callback interface to notify the application when the request has completed. |
state | An arbitrary object used to identify the request when it returns to the callback. This has no effect on the request itself. |
request(String, RequestListener)
public void request(String graphPath, RequestListener listener)
พารามิเตอร์ | คำอธิบาย |
---|---|
graphPath | |
listener |
request(String, Bundle, RequestListener, Object)
Make a request to the Facebook Graph API with the given string parameters using an HTTP GET (default method).
See http://developers.facebook.com/docs/api
Note that this method is asynchronous and the callback will be invoked in a background thread; operations that affect the UI will need to be posted to the UI thread or an appropriate handler.
This method is deprecated. See Facebook and Request for more info.
public void request(String graphPath, Bundle parameters, RequestListener listener, Object state)
พารามิเตอร์ | คำอธิบาย |
---|---|
graphPath | Path to resource in the Facebook graph, e.g., to fetch data about the currently logged authenticated user, provide "me", which will fetch http://graph.facebook.com/me |
parameters | Key-value string parameters, e.g. the path "search" with parameters "q" : "facebook" would produce a query for the following graph resource: https://graph.facebook.com/search?q=facebook |
listener | Callback interface to notify the application when the request has completed. |
state | An arbitrary object used to identify the request when it returns to the callback. This has no effect on the request itself. |
request(String, Bundle, RequestListener)
public void request(String graphPath, Bundle parameters, RequestListener listener)
พารามิเตอร์ | คำอธิบาย |
---|---|
graphPath | |
parameters | |
listener |
request(String, Bundle, String, RequestListener, Object)
Make a request to the Facebook Graph API with the given HTTP method and string parameters. Note that binary data parameters (e.g. pictures) are not yet supported by this helper function.
See http://developers.facebook.com/docs/api
Note that this method is asynchronous and the callback will be invoked in a background thread; operations that affect the UI will need to be posted to the UI thread or an appropriate handler.
This method is deprecated. See Facebook and Request for more info.
public void request(String graphPath, Bundle parameters, String httpMethod, RequestListener listener, Object state)
พารามิเตอร์ | คำอธิบาย |
---|---|
graphPath | Path to resource in the Facebook graph, e.g., to fetch data about the currently logged authenticated user, provide "me", which will fetch http://graph.facebook.com/me |
parameters | Key-value string parameters, e.g. the path "search" with parameters {"q" : "facebook"} would produce a query for the following graph resource: https://graph.facebook.com/search?q=facebook |
httpMethod | Http verb, e.g. "POST", "DELETE" |
listener | Callback interface to notify the application when the request has completed. |
state | An arbitrary object used to identify the request when it returns to the callback. This has no effect on the request itself. |