2011-09-02 57 views
0

我想從我的iPhone應用程序閱讀我的粉絲頁面牆,我該怎麼辦?Facebook sdk for ios閱讀粉絲頁面牆

現在我有這個代碼解析圖形API:

-(IBAction)parsing:(id)sender{ 

    [facebook requestWithGraphPath:@"PAGE_ID/feed" andDelegate:self]; 

} 


- (void)request:(FBRequest *)request didReceiveResponse:(NSURLResponse *)response { 
    NSLog(@"received response"); 
} 

- (void)request:(FBRequest *)request didLoad:(id)result { 
    if ([result isKindOfClass:[NSArray class]]) { 
     result = [result objectAtIndex:0]; 
    } 
    // NSArray *data = [result objectForKey:@"data"]; 
    NSArray *from = [result objectForKey:@"from"]; 

    if ([result objectForKey:@"from"]) { 
     for (NSDictionary *name in from) { 
      NSString *myName = [name objectForKey:@"name"]; 
      [self.label2 setText:myName]; 
      NSLog(@" Log: ", myName); 
    } 

但不工作,因爲他不解析:

JSON文件我想分析是這樣的:

{ 
    "data": [ 
     { 
     "id": "105744066144184_231235146928408", 
     "from": { 
      "name": "Alberto ####", 
      "id": "1000013568710###" 
     }, 
     "to": { 
      "data": [ 
       { 
        "name": "########", 
        "category": "News/media", 
        "id": "##########" 
       } 
      ] 
     }, 
     "message": "\u00e8######################################", 
     "type": "status", 
     "created_time": "2011-09-02T18:30:59+0000", 
     "updated_time": "2011-09-02T18:30:59+0000", 
     "likes": { 
      "data": [ 
       { 
        "name": "Luca #####", 
        "id": "###########" 
       } 
      ], 
      "count": 1 
     }, 
     "comments": { 
      "count": 0 
     } 
ecc.. 
+0

* sidenote *:上述代碼不再適用於Facebook iOS SDK 3.x – Raptor

回答

0

我用

NSArray *list = [result valueForKey:@"data"]; 
    for (NSDictionary *dic in list) { 
     NSLog(@"id : %@",[dic valueForKey:@"id"]); 
     NSLog(@"type : %@",[dic valueForKey:@"type"]); 
     if ([[dic valueForKey:@"type"] isEqualToString:@"status"]) { 
      NSLog(@"- message : %@",[dic valueForKey:@"message"]); 
     }else if([[dic valueForKey:@"type"] isEqualToString:@"link"]){ 
      NSLog(@"- link : %@",[dic valueForKey:@"link"]); 
     }else if([[dic valueForKey:@"type"] isEqualToString:@"photo"]){ 
      NSLog(@"- icon : %@",[dic valueForKey:@"icon"]); 
      NSLog(@"- message : %@",[dic valueForKey:@"message"]); 
     } 
     NSLog(@"------"); 
    } 

adaydesign :)