gpt4 book ai didi

ios - iOS Facebook API无法发布具有自定义属性的图形对象

转载 作者:行者123 更新时间:2023-12-01 16:42:17 25 4
gpt4 key购买 nike

我正在关注本教程。

https://developers.facebook.com/docs/ios/open-graph/

发布带有自定义属性的打开图形对象时收到错误消息。

这是我发布故事的方法

- (void) postToFacebookWithMessage:(NSString *)message andImageURL:(NSString*) url withObjectType:(NSString*)objectType withActionType:(NSString*) actionType withTitle:(NSString*) title withCustomProperties:(NSDictionary*) dict

{
NSMutableDictionary * object = [FBGraphObject openGraphObjectForPost];
// specify that this Open Graph object will be posted to Facebook
object.provisionedForPost = YES;

// for og:title
object[@"title"] = title;

// for og:type, this corresponds to the Namespace you've set for your app and the object type name
object[@"type"] = [NSString stringWithFormat:@"app_namespace:%@",objectType]; //graphType; //@"fbogsample:dish";

// for og:description
object[@"description"] = message;

// for og:url, we cover how this is used in the "Deep Linking" section below
object[@"url"] = [NSString stringWithFormat:@"someurl/%@",objectType];

if (dict != nil)
{
[object addEntriesFromDictionary:dict];
}
// for og:image we assign the image that we just staged, using the uri we got as a response
// the image has to be packed in a dictionary like this:

//if there is no url take standard icon.
if (url == nil)
{
url = @"http/some_image.jpg";
}

object[@"image"] = @[@{@"url": url, @"user_generated" : @"false" }];

[FBRequestConnection startForPostOpenGraphObject:object completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error) {
// get the object ID for the Open Graph object that is now stored in the Object API
NSString *objectId = [result objectForKey:@"id"];
NSLog([NSString stringWithFormat:@"object id: %@", objectId]);

// Further code to post the OG story goes here
// create an Open Graph action
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
[action setObject:objectId forKey:objectType];

// create action referencing user owned object
[FBRequestConnection startForPostWithGraphPath:[NSString stringWithFormat:@"/me/muffins_coffins:%@",actionType] graphObject:action completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error) {
NSLog([NSString stringWithFormat:@"OG story posted, story id: %@", [result objectForKey:@"id"]]);

} else {
// An error occurred
NSLog(@"Encountered an error posting to Open Graph: %@", error);
}
}];

} else {
// An error occurred
NSLog(@"Error posting the Open Graph object to the Object API: %@", error);
}
}];

}

我用这个来调用方法。
     NSMutableDictionary* dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:opponentName,@"app_namespace:opponentname",
opponentId,@"app_namespace:opponentid", levelName,@"app_namespace:levelname", nil];

[appDelegate postToFacebookWithMessage:@"some message" andImageURL:nil
withObjectType:@"match" withActionType:@"won" withTitle:@"Match finished"
withCustomProperties:dict];

这是发送对象之前的对象。
Printing description of object:
{
data = {
};
description = "some description";
"fbsdk:create_object" = 1;
image = (
{
url = "some_image.jpg";
"user_generated" = false;
}
);
"app_namespace:levelname" = "level 3";
"app_namespace:opponentid" = 100007390148688;
"app_namespace:opponentname" = "Some name";
title = "Match finished";
type = "app_namespace:match";
url = "://www.somewebsite/match";
}

这是我得到的错误。
Printing description of error->_userInfo:
{
"com.facebook.sdk:ErrorSessionKey" = "<FBSession: 0x1cd5ccd0, state: FBSessionStateOpen, loginHandler: 0x3e4d50, appID: 1436791226553400, urlSchemeSuffix: , tokenCachingStrategy:<FBSessionTokenCachingStrategy: 0x1cd4af40>, expirationDate: 2014-06-14 12:29:14 +0000, refreshDate: 2014-04-15 12:31:52 +0000, attemptedRefreshDate: 2014-04-23 16:37:01 +0000, permissions:(\n \"create_note\",\n \"basic_info\",\n \"share_item\",\n \"status_update\",\n \"user_friends\",\n \"publish_actions\",\n \"publish_checkins\",\n \"video_upload\",\n \"publish_stream\",\n \"photo_upload\",\n installed,\n \"public_profile\"\n)>";
"com.facebook.sdk:HTTPStatusCode" = 400;
"com.facebook.sdk:ParsedJSONResponseKey" = {
body = {
error = {
code = 100;
message = "(#100) Object Missing a Required Value: Object at URL 'com/match' of type 'app_namespace:match' is invalid because a required property 'app_namespace:levelname' of type 'string' was not provided.";
type = OAuthException;
};
};
code = 400;
};
}

根据错误,我没有提供app_namespace:levelname,但是据我所知,输入是正确的。那么,这里出了什么问题?我试过没有命名空间,但这给出了相同的错误消息。

根据文档,自定义属性可以像普通属性一样添加到图形对象,所以我不确定为什么会出现此错误。

最佳答案

您应该指定以“http://”开头的“url”,我也遇到了这个问题,最后通过上述解决方案解决了这个问题。祝好运!

关于ios - iOS Facebook API无法发布具有自定义属性的图形对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23250706/

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