【问题标题】:Problems with Facebook-Api publish_stream in iPhone applicationiPhone 应用程序中的 Facebook-Api publish_stream 问题
【发布时间】:2010-09-03 17:05:31
【问题描述】:

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

然而,在这个应用程序中,我需要在用户的墙上发帖而不提示任何对话框。 我在 Facebook 文档中进行了搜索,据我了解,如果我要求用户授予我正确的权限(在本例中为 publish_stream),则该对话框不应再出现。

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

希望你能帮助我。

谢谢。

附:对不起我的英语不好

【问题讨论】:

    标签: iphone objective-c facebook


    【解决方案1】:

    在获得 publish_stream 权限后使用图形 API。你发一个 POST 到:

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

    此 iPhone SDK 本身不支持此功能,您必须自己实现此功能。您需要确保创建正确的 JSON 编码参数并确保它们被正确转义。 一个很好的起点是here

    【讨论】:

      【解决方案2】:

      谢谢! 所以,如果我理解得很好,我必须这样做:

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

      再次感谢您。

      【讨论】:

      • 看起来不错 :) 另外,如果我的回答是您想要的,别忘了接受它作为答案
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-05
      • 2011-04-26
      • 2015-01-31
      • 2023-03-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多