本文整理汇总了Java中com.facebook.android.Util类的典型用法代码示例。如果您正苦于以下问题:Java Util类的具体用法?Java Util怎么用?Java Util使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Util类属于com.facebook.android包,在下文中一共展示了Util类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPublicApi
import com.facebook.android.Util; //导入依赖的package包/类
public boolean testPublicApi() {
Facebook fb = new Facebook(APP_ID);
try {
Log.d("Tests", "Testing standard API call");
JSONObject response = Util.parseJson(fb.request("4"));
if (!response.getString("name").equals("Mark Zuckerberg")) {
return false;
}
Log.d("Tests", "Testing an API call with a specific method");
response = Util.parseJson(
fb.request("soneff", new Bundle(), "GET"));
if (!response.getString("name").equals("Steven Soneff")) {
return false;
}
Log.d("Tests", "Testing a public search query");
Bundle params = new Bundle();
params.putString("q", "facebook");
response = Util.parseJson(fb.request("search", params));
if (response.getJSONArray("data").length() == 0) return false;
Log.d("Tests", "Public API Tests passed");
return true;
} catch (Throwable e) {
e.printStackTrace();
return false;
}
}
示例2: onComplete
import com.facebook.android.Util; //导入依赖的package包/类
public void onComplete(final String response, final Object state) {
Log.d("Tests", "Got response: " + response);
try {
JSONObject json = Util.parseJson(response);
//final String message = json.getString("message");
String postId = json.getString("id");
Tests.this.runOnUiThread(new Runnable() {
public void run() {
wallPostText.setText("Wall Post Success");
wallPostText.setTextColor(Color.GREEN);
}
});
Log.d("Tests", "Testing wall post delete");
if (testPostDelete(postId)) {
Tests.this.runOnUiThread(new Runnable() {
public void run() {
deletedPostText.setText("Deleted Post Success");
deletedPostText.setTextColor(Color.GREEN);
}
});
} else {
Tests.this.runOnUiThread(new Runnable() {
public void run() {
deletedPostText.setText("Deleted Post Failure");
deletedPostText.setTextColor(Color.RED);
}
});
}
} catch (Throwable e) {
e.printStackTrace();
Tests.this.runOnUiThread(new Runnable() {
public void run() {
wallPostText.setText("Wall Post Failure");
wallPostText.setTextColor(Color.RED);
}
});
}
}
示例3: shouldOverrideUrlLoading
import com.facebook.android.Util; //导入依赖的package包/类
@Override
@SuppressWarnings("deprecation")
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Utility.logd(LOG_TAG, "Redirect URL: " + url);
if (url.startsWith(WebDialog.REDIRECT_URI)) {
Bundle values = Util.parseUrl(url);
String error = values.getString("error");
if (error == null) {
error = values.getString("error_type");
}
String errorMessage = values.getString("error_msg");
if (errorMessage == null) {
errorMessage = values.getString("error_description");
}
String errorCodeString = values.getString("error_code");
int errorCode = FacebookRequestError.INVALID_ERROR_CODE;
if (!Utility.isNullOrEmpty(errorCodeString)) {
try {
errorCode = Integer.parseInt(errorCodeString);
} catch (NumberFormatException ex) {
errorCode = FacebookRequestError.INVALID_ERROR_CODE;
}
}
if (Utility.isNullOrEmpty(error) && Utility
.isNullOrEmpty(errorMessage) && errorCode == FacebookRequestError.INVALID_ERROR_CODE) {
sendSuccessToListener(values);
} else if (error != null && (error.equals("access_denied") ||
error.equals("OAuthAccessDeniedException"))) {
sendCancelToListener();
} else {
FacebookRequestError requestError = new FacebookRequestError(errorCode, error, errorMessage);
sendErrorToListener(new FacebookServiceException(requestError, errorMessage));
}
WebDialog.this.dismiss();
return true;
} else if (url.startsWith(WebDialog.CANCEL_URI)) {
sendCancelToListener();
WebDialog.this.dismiss();
return true;
} else if (url.contains(DISPLAY_TOUCH)) {
return false;
}
// launch non-dialog URLs in a full browser
getContext().startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return true;
}
示例4: testAuthenticatedApi
import com.facebook.android.Util; //导入依赖的package包/类
public boolean testAuthenticatedApi() {
if (!authenticatedFacebook.isSessionValid()) return false;
try {
Log.d("Tests", "Testing request for 'me'");
String response = authenticatedFacebook.request("me");
JSONObject obj = Util.parseJson(response);
if (obj.getString("name") == null ||
obj.getString("name").equals("")) {
return false;
}
Log.d("Tests", "Testing graph API wall post");
Bundle parameters = new Bundle();
parameters.putString("message", "hello world");
parameters.putString("description", "test test test");
response = authenticatedFacebook.request("me/feed", parameters,
"POST");
Log.d("Tests", "got response: " + response);
if (response == null || response.equals("") ||
response.equals("false")) {
return false;
}
Log.d("Tests", "Testing graph API delete");
response = response.replaceAll("\\{\"id\":\"", "");
response = response.replaceAll("\"\\}", "");
response = authenticatedFacebook.request(response, new Bundle(),
"DELETE");
if (!response.equals("true")) return false;
Log.d("Tests", "Testing old API wall post");
parameters = new Bundle();
parameters.putString("method", "stream.publish");
parameters.putString("attachment",
"{\"name\":\"Name=Title\"," +
"\"href\":\"http://www.google.fr/\",\"" +
"caption\":\"Caption\",\"description\":\"Description" +
"\",\"media\":[{\"type\":\"image\",\"src\":" +
"\"http://www.kratiroff.com/logo-facebook.jpg\"," +
"\"href\":\"http://developers.facebook.com/\"}]," +
"\"properties\":{\"another link\":{\"text\":\"" +
"Facebook homepage\",\"href\":\"http://www.facebook." +
"com\"}}}");;
response = authenticatedFacebook.request(parameters);
Log.d("Tests", "got response: " + response);
if (response == null || response.equals("") ||
response.equals("false")) {
return false;
}
Log.d("Tests", "Testing wall post delete");
response = response.replaceAll("\"", "");
response = authenticatedFacebook.request(
response, new Bundle(), "DELETE");
if (!response.equals("true")) return false;
Log.d("Tests", "All Authenticated Tests Passed");
return true;
} catch (Throwable e) {
e.printStackTrace();
return false;
}
}