「5 - オープン グラフ ストーリーの公開」チュートリアルを文字通り実行しましたが、いくつかの問題に直面しています。Graph API Explorer を使用すると、コードはエラーや警告を生成せず、タイムラインに正しく表示されます。スナップショットを表示するには、リンクをクリックしてください ( http://drsolution.com.br/testes/starbuzz/open%20graph.png )。しかし、私のアプリが同じ種類のコードを生成し、グラフを開くと、オブジェクトやアクションではなく、写真のみがアップロードされます。( http://drsolution.com.br/testes/starbuzz/posted%20by%20ios%20app.png )
コードは次のとおりです。
- (IBAction)publicar:(UIButton *)sender {
if ([FBSession.activeSession.permissions
indexOfObject:@"publish_actions"] == NSNotFound) {
[FBSession.activeSession
reauthorizeWithPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
if (!error) {
// re-call assuming we now have the permission
[self publicar:sender];
}
}];
} else {
if (self.selectedPhoto) {
[self postPhotoThenOpenGraphAction];
} else {
[self postOpenGraphActionWithPhotoURL:nil];
}
}
}
#pragma mark - SCOGProblema and SCOGDenunciarProblema protocols
- (id<SCOGProblema>)problemaObjectForMeal:(NSString*)problema
{
// This URL is specific to this sample, and can be used to
// create arbitrary OG objects for this app; your OG objects
// will have URLs hosted by your server.
NSString *format =
@"https://boiling-spire-2233.herokuapp.com/index.php?"
@"fb:app_id=412805615466140&og:type=%@&"
@"og:title=%@&og:description=%%22%@%%22&"
@"og:image=https://s-static.ak.fbcdn.net/images/devsite/attachment_blank.png&"
@"body=%@";
// We create an FBGraphObject object, but we can treat it as
// an SCOGMeal with typed properties, etc. See <FacebookSDK/FBGraphObject.h>
// for more details.
id<SCOGProblema> result = (id<SCOGProblema>)[FBGraphObject graphObject];
// Give it a URL that will echo back the name of the meal as its title,
// description, and body.
result.url = [NSString stringWithFormat:format,
@"orgdrsolutionpery:problema", problema, problema, problema];
return result;
}
-(void) postOpenGraphActionWithPhotoURL:(NSString *)photoURL
{
// First create the Open Graph meal object for the meal we ate.
id<SCOGProblema> problemaObject = [self problemaObjectForMeal:self.problema];
NSLog(@"%@",problemaObject);
// Now create an Open Graph eat action with the meal, our location,
// and the people we were with.
id<SCOGDenunciarProblemaAction> action =
(id<SCOGDenunciarProblemaAction>)[FBGraphObject graphObject];
action.problema = problemaObject;
if (self.selectedPlace) {
action.place = self.selectedPlace;
}
if (photoURL) {
NSMutableDictionary *image = [[NSMutableDictionary alloc] init];
[image setObject:photoURL forKey:@"url"];
NSMutableArray *images = [[NSMutableArray alloc] init];
[images addObject:image];
action.image = images;
}
// Create the request and post the action to the
// "me/<YOUR_APP_NAMESPACE>:eat" path.
[FBRequestConnection startForPostWithGraphPath:@"me/orgdrsolutionpery:denuncia"
graphObject:action
completionHandler:
^(FBRequestConnection *connection, id result, NSError *error) {
NSString *alertText;
if (!error) {
alertText = [NSString stringWithFormat:
@"Posted Open Graph action, id: %@",
[result objectForKey:@"id"]];
} else {
alertText = [NSString stringWithFormat:
@"error: domain = %@, code = %d",
error.domain, error.code];
}
[[[UIAlertView alloc] initWithTitle:@"Result"
message:alertText
delegate:nil
cancelButtonTitle:@"Thanks!"
otherButtonTitles:nil]
show];
}
];
}
- (void)postPhotoThenOpenGraphAction
{
[FBSettings setLoggingBehavior:[NSSet
setWithObjects:FBLoggingBehaviorFBRequests,
FBLoggingBehaviorFBURLConnections,
nil]];
FBRequestConnection *connection = [[FBRequestConnection alloc] init];
// First request uploads the photo.
FBRequest *request1 = [FBRequest
requestForUploadPhoto:self.selectedPhoto];
[connection addRequest:request1
completionHandler:
^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
}
}
batchEntryName:@"photopost"
];
// Second request retrieves photo information for just-created
// photo so we can grab its source.
FBRequest *request2 = [FBRequest
requestForGraphPath:@"{result=photopost:$.id}"];
[connection addRequest:request2
completionHandler:
^(FBRequestConnection *connection, id result, NSError *error) {
if (!error &&
result) {
NSString *source = [result objectForKey:@"source"];
[self postOpenGraphActionWithPhotoURL:source];
}
}
];
[connection start];