代码之家  ›  专栏  ›  技术社区  ›  Sylter

iPhone应用程序中Facebook Api发布流的问题

  •  0
  • Sylter  · 技术社区  · 15 年前

    我在新的iPhone应用程序中添加了Facebook Connect。一切都很完美,没问题。

    然而,在这个应用程序中,我需要在用户的墙上张贴而不提示任何对话框。

    尽管如此,盒子还是出现了。

    我希望你能帮助我。

    非常感谢。

    对不起,我的英语不好

    2 回复  |  直到 15 年前
        1
  •  1
  •   BeRecursive    15 年前

    在获得“发布流”权限后使用graph API。你发了一个帖子到:

    https://graph.facebook.com/ID/feed
    

    此iphonesdk本机不支持此功能,您必须自己实现此功能。您需要确保您创建了正确的JSON编码参数,并确保它们被正确转义。 一个好的开始是 here

        2
  •  0
  •   Sylter    15 年前

    谢谢您!

    http://code.google.com/p/json-framework/ 添加JSON支持。

    这个代码是:

    SBJSON *json = [SBJSON new];
    
      json.humanReadable = YES;
    
      NSString *service = @"NameService";
    
      NSMutableDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
                                      @"MessaggeFromMyApp",@"message",
                                      @"http://www.sample.com",@"link",
                                       @"nomeOfTheLink",@"name",
                                      @"captionOfTheLink",@"caption",
                                       @"descriptionofTheLink",@"description",
                                       @"MyDistrict",@"value",
                                       @"2",@"txs_Action",
                                       nil];
        //Pass it twice to escape quotes
      NSString *jsonString = [NSString stringWithFormat:@"%@", [params JSONFragment], nil];
    
      NSString *changeJSON = [NSString stringWithFormat:@"%@", [jsonString JSONFragment], nil];
    
        NSLog(jsonString);
        NSLog(changeJSON);
    
    
        NSString *requestString = [NSString stringWithFormat:@"{\"id\":15,\"method\":\"%@\",\"params\":[%@]}",service,changeJSON,nil];
        NSLog(requestString);
    
    
        NSData *requestData = [NSData dataWithBytes: [requestString UTF8String] length: [requestString length]];
    
    
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: @"https://graph.facebook.com/me/feed"]];
    
        NSString *postLength = [NSString stringWithFormat:@"%d", [requestData length]];
        [request setHTTPMethod: @"POST"];
        [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
        [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
        [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
        [request setHTTPBody: requestData];
    
        //Data returned by WebService
        NSData *returnData = [NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil ];
        NSString *returnString = [[NSString alloc] initWithData:returnData encoding: NSUTF8StringEncoding];
    
        NSLog(returnString);
    

    再次感谢你。

    推荐文章