2014-09-02 1 views
0

Open Graph를 처음 접했을 때 Facebook 튜토리얼이나 문서에서 어디에서이 작업을 수행하는지 알려지지 않습니다. 이것은 내가 내 문장오픈 그래프 스토리를 사용자 정의하는 방법은 무엇입니까?

I just got a score of *350*! Can you beat it? 

말하고 싶은하지만 오픈 그래프 이야기에 추가 내 self.score을하는 방법을 모른다 엑스 코드 (6)

에 아이폰 OS 8 일에 이루어집니다!

Facebook의 튜토리얼이 오래되어 표시 할 수있는 코드가 없습니다. 누구든지 위의 줄을 게시하기 위해 사용자 지정 Open Graph (또는 더 나은 솔루션)에 오류가없는 더 나은 코드를 제공해 주시면 매우 감사하겠습니다.

답변

0

페이스 북 코드가 잘못 되었기 때문에 나는 그것을 어떻게 할 방법을 찾았는지 설명하고 전체 코드를 게시합니다.

오픈 그래프 아이디어를 잊어 버렸고 버튼으로 트리거 된 간단한 조건부 문자열을 게시하기로 결정했습니다. 거기에서 나는 페이스 북의 코드를 here에서 사용했고, 단지 "Share Dialog"가 완전히 작동하지 않기 때문에 폴백을 사용했다.

-(IBAction)facebookShare:(id)sender { 

//Set Variables 
int scoreText 
int highScoreText 

//Format the description 
NSString *description; 
NSString *t1 = @"I just got a score of "; 
NSString *t1Alt = @"I just got a new high score of "; 
NSString *t2 = @"! Can you beat it?"; 
if (self.newHigh == NO){ 
    description = [NSString stringWithFormat:@"%@%@%@",t1,scoreText,t2]; 
} else if (self.newHigh == YES){ 
    description = [NSString stringWithFormat:@"%@%@%@",t1Alt,highScoreText,t2]; 
} 

// Put together the dialog parameters 
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys: 
           @"Edit Me", @"name", 
           @"Edit Me", @"caption", 
           description, @"description", 
           @"http://Edit.Me.Too/", @"link", 
           @"http://And.Me.Too/", @"picture", 
           nil]; 

/* * * * * * * * * * * DO NOT EDIT BELOW THIS LINE * * * * * * * * * * * * 
*                  * 
*                  * 
*    From here on, this shows share screen     *       
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 
[FBWebDialogs presentFeedDialogModallyWithSession:nil 
             parameters:params 
              handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) { 
               if (error) { 
                // An error occurred, we need to handle the error 
                // See: https://developers.facebook.com/docs/ios/errors 
                NSLog(@"Error publishing story: %@", error.description); 
               } else { 
                if (result == FBWebDialogResultDialogNotCompleted) { 
                 // User cancelled. 
                 NSLog(@"User cancelled."); 
                } else { 
                 // Handle the publish feed callback 
                 NSDictionary *urlParams = [self parseURLParams:[resultURL query]]; 

                 if (![urlParams valueForKey:@"post_id"]) { 
                  // User cancelled. 
                  NSLog(@"User cancelled."); 

                 } else { 
                  // User clicked the Share button 
                  NSString *result = [NSString stringWithFormat: @"Posted story, id: %@", [urlParams valueForKey:@"post_id"]]; 
                  NSLog(@"result %@", result); 
                 } 
                } 
               } 
              }]; 

}

: 거기에서

난 그냥 여기

[NSString stringWithFormat:%@%@%@,string1,self.score,string2];가 (다른 사람에 대한 일반적인 것으로 수정) 샘플 코드 사용

관련 문제