2011-09-09 69 views
4

我必須在我的應用程序中集成雅虎api。任何人都可以提供我的步驟嗎?Yahoo API集成?

由於我們已經集成了雅虎,我們從雅虎獲得了一個tokenkey,並且在輸入密鑰之後,我們進入了應用程序。是否有任何人在進行了雅虎登錄後直接進入應用程序。

回答

1

下面是使用雅虎的XML代碼部分的子集解答。我寫了這個寫我自己的答案應用程序。

NSString *question = @"Who won the 1975 World Series?"; 
    NSString *address = @"http://answers.yahooapis.com/AnswersService/V1/questionSearch?appid=iQuestion&query="; 
    NSString *request = [NSString stringWithFormat:@"%@%@",address,question]; 
    NSURL *URL = [NSURL URLWithString:request]; 
    NSError *error;  
    NSString *XML = [NSString stringWithContentsOfURL:URL encoding:NSASCIIStringEncoding error:&error]; 

    // Extract current answer the 'dirty' way 
    NSString *answer = [[[[XML componentsSeparatedByString:@"<ChosenAnswer>"] 
    objectAtIndex:1] componentsSeparatedByString:@"</ChosenAnswer>"] objectAtIndex:0]; 
    NSLog(@"%@", answer); 

的XML提取是非常粗略的,如果你願意的最佳替代方案是使用一個XmlParser或爲XMLDocument,而不是做一個String推斷。這有點貧民窟