gpt4 book ai didi

Android 如何在新的 sdk 3.0 中与 Facebook Open Graph 共享数据?

转载 作者:行者123 更新时间:2023-11-29 17:54:26 24 4
gpt4 key购买 nike

现在我已经在 Facebook 上设置了我的 Open Graph 应用程序。它已被批准。我正在尝试通过 bundle params 提交我的“对象”,但我很好奇我是如何设置 bundle param 对象的,如下所示。

编辑:

我正在像这样创建对象和 Action

Objectsaction 这是分享代码

  void publishToWall() {        
Session session = Session.getActiveSession();
if (session != null) {
Log.i("session ==>", "" +session);
// Check for publish permissions
List<String> permissions = session.getPermissions();
if (!isSubsetOf(PERMISSIONS, permissions)) {
Log.i("session permissions ==>", "publishToWall");
pendingPublishReauthorization = true;
Session.NewPermissionsRequest newPermissionsRequest = new Session
.NewPermissionsRequest(this, PERMISSIONS);
session.requestNewPublishPermissions(newPermissionsRequest);
return;
}

try {
RequestBatch requestBatch = new RequestBatch();
Log.i("session requestBatch ==>", "requestBatch");

JSONObject tropy = new JSONObject();

tropy.put("type", "thebigtoss:tropy");
tropy.put("title", "A Game of Thrones");
tropy.put("url","http://www.thebigtoss.com/assets/app-icon.png");
tropy.put("description", "supernatural forces are mustering.");

// Set up object request parameters
Bundle objectParams = new Bundle();
objectParams.putString("object", tropy.toString());
// Set up the object request callback
Request.Callback objectCallback = new Request.Callback() {
@Override
public void onCompleted(Response response) {
Log.i("objectParams onCompleted ==>", "onCompleted");
// Log any response error
FacebookRequestError error = response.getError();
if (error != null) {
Log.i(TAG, "objectParams =>" +error.getErrorMessage());
}
}
};
// Create the request for object creation
Request objectRequest = new Request(session,
"me/objects/thebigtoss:trophy", objectParams, HttpMethod.POST, objectCallback);

// Set the batch name so you can refer to the result
// in the follow-on publish action request
// objectRequest.setBatchEntryName("objectCreate");

// Add the request to the batch
requestBatch.add(objectRequest);

Bundle actionParams = new Bundle();
// Refer to the "id" in the result from the previous batch request
actionParams.putString("trophy", "Action parametery");
// Turn on the explicit share flag
actionParams.putString("fb:explicitly_shared", "true");

// Set up the action request callback
Request.Callback actionCallback = new Request.Callback() {
@Override
public void onCompleted(Response response) {
// dismissProgressDialog();
FacebookRequestError error = response.getError();
if (error != null) {
Toast.makeText(MainActivity.this.getApplicationContext(),error.getErrorMessage(),Toast.LENGTH_LONG).show();
} else {
String actionId = null;
try {
JSONObject graphResponse = response.getGraphObject().getInnerJSONObject();
actionId = graphResponse.getString("id");
} catch (JSONException e) {
Log.i(TAG, "JSON error "+ e.getMessage());
}
Toast.makeText(MainActivity.this.getApplicationContext(),actionId, Toast.LENGTH_LONG).show();
}
}
};
// Create the publish action request
Request actionRequest = new Request(session,
"me/thebigtoss:win", actionParams, HttpMethod.POST, actionCallback);
// Add the request to the batch
requestBatch.add(actionRequest);
// Execute the batch request
requestBatch.executeAsync();

} catch (JSONException e) {
//Auto-generated catch block
e.printStackTrace();
}
}
}

但我没有在我的 facebook 上分享数据

这个错误是 12-10 15:26:25.710: I/MainActivity(27667): objectParams =>(#100) conflicting og:type found in path (thebigtoss:trophy) and 'properties' (thebigtoss:tropy)

if (error != null) {<br/>
Log.i(TAG, "objectParams =>" +error.getErrorMessage());
的代码行中

Request.Callback objectCallback = new Request.Callback() {
@Override
public void onCompleted(Response response) {
Log.i("objectParams onCompleted ==>", "onCompleted");
// Log any response error
FacebookRequestError error = response.getError();
if (error != null) {
Log.i(TAG, "objectParams =>" +error.getErrorMessage());
}
}
};

任何人都知道如何在 facebook opengraph 中使用此代码分享。

最佳答案

您不能只将一个打开的图形对象/操作放在一个 Bundle 中。

首先您需要创建一个 OpenGraphObject:

OpenGraphObject object = OpenGraphObject.Factory.createForPost("yournamespace:objectname");
object.setTitle("Sample Trophy");
object.setDescription("...");
//... set more properties as necessary

然后创建一个 OpenGraphAction 并将您的对象添加到其中:

OpenGraphAction action = OpenGraphAction.Factory.createForPost("thebigtoss:win");
action.setProperty("trophy", object);

最后,使用 newPostOpenGraphActionRequest 方法发布:

Request request = Request.newPostOpenGraphActionRequest(session, action, new Callback() {...});

关于Android 如何在新的 sdk 3.0 中与 Facebook Open Graph 共享数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20472897/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com