本文整理汇总了Java中com.facebook.model.OpenGraphObject类的典型用法代码示例。如果您正苦于以下问题:Java OpenGraphObject类的具体用法?Java OpenGraphObject怎么用?Java OpenGraphObject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OpenGraphObject类属于com.facebook.model包,在下文中一共展示了OpenGraphObject类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: newPostOpenGraphObjectRequest
import com.facebook.model.OpenGraphObject; //导入依赖的package包/类
/**
* Creates a new Request configured to create a user owned Open Graph object.
*
* @param session
* the Session to use, or null; if non-null, the session must be in an opened state
* @param openGraphObject
* the Open Graph object to create; must not be null, and must have a non-empty type and title
* @param callback
* a callback that will be called when the request is completed to handle success or error conditions
* @return a Request that is ready to execute
*/
public static Request newPostOpenGraphObjectRequest(Session session,
OpenGraphObject openGraphObject, Callback callback) {
if (openGraphObject == null) {
throw new FacebookException("openGraphObject cannot be null");
}
if (Utility.isNullOrEmpty(openGraphObject.getType())) {
throw new FacebookException("openGraphObject must have non-null 'type' property");
}
if (Utility.isNullOrEmpty(openGraphObject.getTitle())) {
throw new FacebookException("openGraphObject must have non-null 'title' property");
}
String path = String.format(MY_OBJECTS_FORMAT, openGraphObject.getType());
Bundle bundle = new Bundle();
bundle.putString(OBJECT_PARAM, openGraphObject.getInnerJSONObject().toString());
return new Request(session, path, bundle, HttpMethod.POST, callback);
}
示例2: newUpdateOpenGraphObjectRequest
import com.facebook.model.OpenGraphObject; //导入依赖的package包/类
/**
* Creates a new Request configured to update a user owned Open Graph object.
*
* @param session
* the Session to use, or null; if non-null, the session must be in an opened state
* @param openGraphObject
* the Open Graph object to update, which must have a valid 'id' property
* @param callback
* a callback that will be called when the request is completed to handle success or error conditions
* @return a Request that is ready to execute
*/
public static Request newUpdateOpenGraphObjectRequest(Session session, OpenGraphObject openGraphObject,
Callback callback) {
if (openGraphObject == null) {
throw new FacebookException("openGraphObject cannot be null");
}
String path = openGraphObject.getId();
if (path == null) {
throw new FacebookException("openGraphObject must have an id");
}
Bundle bundle = new Bundle();
bundle.putString(OBJECT_PARAM, openGraphObject.getInnerJSONObject().toString());
return new Request(session, path, bundle, HttpMethod.POST, callback);
}
示例3: shareToFB
import com.facebook.model.OpenGraphObject; //导入依赖的package包/类
private void shareToFB(Context context, String badgeName) {
String description = context.getResources().getText(context.getResources()
.getIdentifier(badgeName + "FB", "string", context.getPackageName())).toString();
String imgURL = context.getResources().getText(context.getResources()
.getIdentifier(badgeName + "imgURL", "string", context.getPackageName())).toString();
if (FacebookDialog.canPresentOpenGraphActionDialog(context.getApplicationContext(),
FacebookDialog.OpenGraphActionDialogFeature.OG_ACTION_DIALOG)) {
OpenGraphObject badge = OpenGraphObject.Factory.createForPost
(OpenGraphObject.class, "exercisemeapp:badge", "I earned a new badge!",
imgURL, null, description);
OpenGraphAction action = GraphObject.Factory.create(OpenGraphAction.class);
action.setProperty("badge", badge);
action.setType("exercisemeapp:earn");
FacebookDialog shareDialog = new FacebookDialog.OpenGraphActionDialogBuilder(getActivity(), action, "badge")
.build();
uiHelper.trackPendingDialogCall(shareDialog.present());
} else {
Toast.makeText(getActivity(), "Facebook not available", Toast.LENGTH_SHORT).show();
}
}
示例4: testOpenGraphObjectImageAttachments
import com.facebook.model.OpenGraphObject; //导入依赖的package包/类
public void testOpenGraphObjectImageAttachments() throws JSONException {
OpenGraphAction action = OpenGraphAction.Factory.createForPost("foo");
OpenGraphObject object = OpenGraphObject.Factory.createForPost("bar");
action.setProperty("foo", object);
FacebookDialog.OpenGraphActionDialogBuilder builder =
new FacebookDialog.OpenGraphActionDialogBuilder(getActivity(), action, "foo");
Bitmap bitmap = Bitmap.createBitmap(20, 20, Bitmap.Config.ALPHA_8);
builder.setImageAttachmentsForObject("foo", Arrays.asList(bitmap));
List<GraphObject> images = object.getImage();
assertNotNull(images);
assertTrue(images.size() == 1);
List<String> attachmentNames = builder.getImageAttachmentNames();
assertNotNull(attachmentNames);
assertTrue(attachmentNames.size() == 1);
String attachmentName = getAttachmentNameFromContentUri((String) images.get(0).getProperty("url"));
assertEquals(attachmentNames.get(0), attachmentName);
}
示例5: shareToFB
import com.facebook.model.OpenGraphObject; //导入依赖的package包/类
public static void shareToFB(Activity activity, String quoteText, UiLifecycleHelper uiHelper) {
if (FacebookDialog.canPresentOpenGraphActionDialog(activity.getApplicationContext(),
FacebookDialog.OpenGraphActionDialogFeature.OG_ACTION_DIALOG)) {
OpenGraphObject quote = OpenGraphObject.Factory.createForPost
(OpenGraphObject.class, "speakeasydevfest:post", "I loved this quote!",
"http://i.imgur.com/ec9p33P.jpg", null, "\"" + quoteText + "\"");
OpenGraphAction action = GraphObject.Factory.create(OpenGraphAction.class);
action.setProperty("quote", quote);
action.setType("speakeasydevfest:love");
FacebookDialog shareDialog = new FacebookDialog.OpenGraphActionDialogBuilder(activity, action, "quote")
.build();
uiHelper.trackPendingDialogCall(shareDialog.present());
} else {
Toast.makeText(activity, "Facebook not available", Toast.LENGTH_SHORT).show();
}
}
示例6: updateObjectAttachmentUrls
import com.facebook.model.OpenGraphObject; //导入依赖的package包/类
void updateObjectAttachmentUrls(String objectProperty, List<String> attachmentUrls, boolean isUserGenerated) {
final OpenGraphObject object;
try {
object = action.getPropertyAs(objectProperty, OpenGraphObject.class);
if (object == null) {
throw new IllegalArgumentException("Action does not contain a property '" + objectProperty + "'");
}
} catch (FacebookGraphObjectException exception) {
throw new IllegalArgumentException("Property '" + objectProperty + "' is not a graph object");
}
if (!object.getCreateObject()) {
throw new IllegalArgumentException(
"The Open Graph object in '" + objectProperty + "' is not marked for creation");
}
GraphObjectList<GraphObject> attachments = object.getImage();
if (attachments == null) {
attachments = GraphObject.Factory.createList(GraphObject.class);
}
for (String url : attachmentUrls) {
GraphObject graphObject = GraphObject.Factory.create();
graphObject.setProperty(NativeProtocol.IMAGE_URL_KEY, url);
if (isUserGenerated) {
graphObject.setProperty(NativeProtocol.IMAGE_USER_GENERATED_KEY, true);
}
attachments.add(graphObject);
}
object.setImage(attachments);
}
示例7: newPostOpenGraphObjectRequest
import com.facebook.model.OpenGraphObject; //导入依赖的package包/类
public static Request newPostOpenGraphObjectRequest(Session paramSession, OpenGraphObject paramOpenGraphObject, Callback paramCallback)
{
if (paramOpenGraphObject == null)
throw new FacebookException("openGraphObject cannot be null");
if (Utility.isNullOrEmpty(paramOpenGraphObject.getType()))
throw new FacebookException("openGraphObject must have non-null 'type' property");
if (Utility.isNullOrEmpty(paramOpenGraphObject.getTitle()))
throw new FacebookException("openGraphObject must have non-null 'title' property");
Object[] arrayOfObject = new Object[1];
arrayOfObject[0] = paramOpenGraphObject.getType();
String str = String.format("me/objects/%s", arrayOfObject);
Bundle localBundle = new Bundle();
localBundle.putString("object", paramOpenGraphObject.getInnerJSONObject().toString());
return new Request(paramSession, str, localBundle, HttpMethod.POST, paramCallback);
}
示例8: newUpdateOpenGraphObjectRequest
import com.facebook.model.OpenGraphObject; //导入依赖的package包/类
public static Request newUpdateOpenGraphObjectRequest(Session paramSession, OpenGraphObject paramOpenGraphObject, Callback paramCallback)
{
if (paramOpenGraphObject == null)
throw new FacebookException("openGraphObject cannot be null");
String str = paramOpenGraphObject.getId();
if (str == null)
throw new FacebookException("openGraphObject must have an id");
Bundle localBundle = new Bundle();
localBundle.putString("object", paramOpenGraphObject.getInnerJSONObject().toString());
return new Request(paramSession, str, localBundle, HttpMethod.POST, paramCallback);
}
示例9: testCantSetObjectAttachmentsWithNullBitmaps
import com.facebook.model.OpenGraphObject; //导入依赖的package包/类
public void testCantSetObjectAttachmentsWithNullBitmaps() {
try {
OpenGraphAction action = OpenGraphAction.Factory.createForPost("foo");
action.setProperty("foo", OpenGraphObject.Factory.createForPost("bar"));
FacebookDialog.OpenGraphActionDialogBuilder builder =
new FacebookDialog.OpenGraphActionDialogBuilder(getActivity(), action, "foo");
builder.setImageAttachmentsForObject("foo", Arrays.asList((Bitmap)null));
fail("expected exception");
} catch (NullPointerException exception) {
}
}
示例10: testOpenGraphActionAndObjectImageAttachments
import com.facebook.model.OpenGraphObject; //导入依赖的package包/类
public void testOpenGraphActionAndObjectImageAttachments() throws JSONException {
OpenGraphAction action = OpenGraphAction.Factory.createForPost("foo");
OpenGraphObject object = OpenGraphObject.Factory.createForPost("bar");
action.setProperty("foo", object);
FacebookDialog.OpenGraphActionDialogBuilder builder =
new FacebookDialog.OpenGraphActionDialogBuilder(getActivity(), action, "foo");
Bitmap bitmap = Bitmap.createBitmap(20, 20, Bitmap.Config.ALPHA_8);
builder.setImageAttachmentsForAction(Arrays.asList(bitmap));
builder.setImageAttachmentsForObject("foo", Arrays.asList(bitmap));
List<String> attachmentNames = builder.getImageAttachmentNames();
assertNotNull(attachmentNames);
assertTrue(attachmentNames.size() == 2);
List<GraphObject> objectImages = object.getImage();
assertNotNull(objectImages);
assertTrue(objectImages.size() == 1);
String attachmentName = getAttachmentNameFromContentUri((String) objectImages.get(0).getProperty("url"));
assertTrue(attachmentNames.contains(attachmentName));
List<JSONObject> actionImages = action.getImage();
assertNotNull(actionImages);
assertTrue(actionImages.size() == 1);
attachmentName = getAttachmentNameFromContentUri((String) actionImages.get(0).getString("url"));
assertTrue(attachmentNames.contains(attachmentName));
}
示例11: testOpenGraphDialogBuilderDeprecatedConstructorRequiresActionType
import com.facebook.model.OpenGraphObject; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public void testOpenGraphDialogBuilderDeprecatedConstructorRequiresActionType() {
try {
OpenGraphAction action = OpenGraphAction.Factory.createForPost();
OpenGraphObject object = OpenGraphObject.Factory.createForPost("bar");
action.setProperty("object", object);
FacebookDialog.OpenGraphActionDialogBuilder builder =
new FacebookDialog.OpenGraphActionDialogBuilder(getActivity(), action, "", "object");
builder.build();
fail("expected exception");
} catch (IllegalArgumentException exception) {
}
}
示例12: testOpenGraphDialogBuilderDeprecatedConstructorRequiresActionTypeMatches
import com.facebook.model.OpenGraphObject; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public void testOpenGraphDialogBuilderDeprecatedConstructorRequiresActionTypeMatches() {
try {
OpenGraphAction action = OpenGraphAction.Factory.createForPost("foo");
OpenGraphObject object = OpenGraphObject.Factory.createForPost("bar");
action.setProperty("object", object);
FacebookDialog.OpenGraphActionDialogBuilder builder =
new FacebookDialog.OpenGraphActionDialogBuilder(getActivity(), action, "notfoo", "object");
builder.build();
fail("expected exception");
} catch (IllegalArgumentException exception) {
}
}
示例13: testOpenGraphDialogBuilderDeprecatedConstructorRequiresActionTypeMatches
import com.facebook.model.OpenGraphObject; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public void testOpenGraphDialogBuilderDeprecatedConstructorRequiresActionTypeMatches() {
try {
OpenGraphAction action = OpenGraphAction.Factory.createForPost("foo");
OpenGraphObject object = OpenGraphObject.Factory.createForPost("bar");
action.setProperty("object", object);
FacebookDialog.OpenGraphActionDialogBuilder builder =
new FacebookDialog.OpenGraphActionDialogBuilder(getActivity(), action, "notfoo", "object");
builder.build();
fail("expected exception");
} catch (IllegalArgumentException exception) {
}
}