2

我已经按照字面意思遵循了“5 - Publish Open Graph Story”教程,但我遇到了一些问题。当我使用 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];
4

0 回答 0