2010-09-03 83 views
0

我已将Facebook Connect添加到我的新iPhone应用程序。一切都很完美,没问题。iPhone应用程序中Facebook-Api publish_stream的问题

但是,在这个应用程序中,我需要在用户的墙上发布任何对话框而不提示任何对话框。 我在Facebook文档中搜索过,据我所知,如果我要求用户给我正确的权限(在本例中为publish_stream),对话框应该不会再出现。

但是尽管如此,盒子仍然出现。

我希望你能帮助我。

谢谢。

P.S.对不起,我的英文不好

回答

1

获得publish_stream权限后使用图形API。您将POST发送至:

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

此iPhone SDK本身不支持此操作,您必须自行实施此操作。您需要确保您创建正确的JSON编码参数并确保它们正确地转义。 从这开始的好地方是here

0

谢谢! 因此,如果我理解的很好,我必须这样做:

使用此框架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); 

再次感谢您。

+0

这看起来不错:)另外,如果我的回复是你正在寻找的,不要忘记接受它作为答案 – BeRecursive 2010-09-03 09:18:05

+0

当然,再次感谢。 下午我会测试代码... – Sylter 2010-09-03 09:39:41