FBConnect facebook.stream.publish 与 NSDictionary 问题

2024-02-20

我有这段代码,到目前为止还无法发送 Facebook 请求。

NSDictionary *firstDict = [NSDictionary dictionaryWithObjectsAndKeys:
    @"image", @"Type",
    @"http://mysite.com/image.jpg", @"src",
    @"http://mysite.com/page.html", @"href",
    nil];
NSDictionary *secondDict = [NSDictionary dictionaryWithObjectsAndKeys:
    @"image", @"Type",
    @"http://mysite.com/image.jpg", @"src",
    @"http://mysite.com/page.html", @"href",
    nil];
NSArray *mediaArray = [[NSArray alloc] initWithObjects:firstDict, secondDict, nil];

NSArray *keys = [NSArray arrayWithObjects:@"name", @"description", @"href", @"media", nil];
NSArray *objects = [NSArray arrayWithObjects:
    [NSString stringWithString:@"MyTitle"],
    [NSString stringWithString:@"My caption"],
    [NSString stringWithString:@"http://mysite.com/page.html"], mediaArray, nil];

NSDictionary *attachment = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
[[FBRequest requestWithDelegate:self] call:@"facebook.stream.publish" params:attachment];

我拿了这个样本:http://forum.developers.facebook.com/viewtopic.php?pid=145965 http://forum.developers.facebook.com/viewtopic.php?pid=145965

但每次运行它时,控制台都会显示以下内容:

 {
     "api_key" = adc8d70987098sdc;
     "call_id" = 23456767;
     description = "Any user's description";
     format = XML;
     href = "http://mysite.com/page.html";
     media =     (
                 {
             Type = image;
             href = "http://mysite.com/page.html";
             src = "http://mysite.com/image.jpg";
         },
                 {
             Type = image;
             href = "http://mysite.com/page.html";
             src = "http://mysite.com/image.jpg";
         }
     );
     method = "Facebook.streamPublish";
     name = aName;
     "session_key" = "d0f98bfs89b7fg7v";
     sig = 89v0d9fv879fgv;
     ss = 1;
     v = "1.0"; }

它显示数组的括号而不是方括号,这正常吗?

然后它显示错误:

*** -[NSCFArray dataUsingEncoding:]: unrecognized selector sent to instance
     0x12fcb0 2009-10-30 13:54:27.758 GeoPixr[307:207]
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
*** -[NSCFArray dataUsingEncoding:]: unrecognized selector sent to instance 0x12fcb0

[sessionresume] 调用返回 TRUE。

提前致谢。


如果您使用的是最新的Facebook 的 iOS SDK http://thinkdiff.net/facebook/how-to-develop-facebook-application-for-iphone/然后使用下面的方法您可以将图像发布为流。




- (IBAction) publishStream: (id)sender {

  SBJSON *jsonWriter = [[SBJSON new] autorelease];

  NSDictionary* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:
                               @"Always Running",@"text",@"http://thinkdiff.net",@"href", nil], nil];

  NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];
  NSDictionary* imageShare = [NSDictionary dictionaryWithObjectsAndKeys:
                                @"image", @"type",
                                @"http://thinkdiff.net/mahmud_small.jpg", @"src",
                                @"http://thinkdiff.net", @"href",
                                nil];

  NSDictionary* attachment = [NSDictionary dictionaryWithObjectsAndKeys:
                               @"a long run", @"name",
                               @"The Facebook Running app", @"caption",
                               @"it is fun", @"description",
                               @"http://itsti.me/", @"href",
                               [NSArray arrayWithObjects:imageShare, nil ], @"media",
                              nil];
  NSString *attachmentStr = [jsonWriter stringWithObject:attachment];
    NSLog(attachmentStr);
  NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                 kAppId, @"api_key",
                                 @"Share on Facebook",  @"user_message_prompt",
                                 actionLinksStr, @"action_links",
                                 attachmentStr, @"attachment",
                                 nil];

  [_facebook dialog: @"stream.publish"
          andParams: params
        andDelegate:self];
}
  

图像部分应该是另一个 NSDictionary 对象。



NSDictionary* imageShare = [NSDictionary dictionaryWithObjectsAndKeys:
                                @"image", @"type",
                                @"http://thinkdiff.net/mahmud_small.jpg", @"src",
                                @"http://thinkdiff.net", @"href",
                                nil];
  

并且在附件中 NSDictionary 对象必须包含 imageShare 对象作为数组



[NSArray arrayWithObjects:imageShare, nil ]
  

这是因为如果您不将其包含为数组,Json 解析器会避免使用 [] 括号,因此发布功能将无法工作。请记住,该字符串必须是有效的 JSON 字符串,否则 facebook api 将不会发布。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

FBConnect facebook.stream.publish 与 NSDictionary 问题 的相关文章

  • iPhone - UIWebView 多重锁定

    我在调试器控制台中收到以下错误消息 bool WebTryThreadLock bool 0x7400460 Multiple locks on web thread not allowed Please file a bug Crashi
  • 在哪里可以找到“get-pip.py”下载链接?

    作为教程的一部分 我尝试下载 pip py 但链接现在不同了 我找不到可以下载 pip 的按钮 这是我得到的链接 https pip pypa io en stable installing cmdoption no setuptools
  • UICollectionView 滚动到任何页脚或页眉视图

    我想滚动到集合视图的页脚或标题视图 但是 标准方法是scrollToItemAtIndexPath仅滚动到单元格 void scrollToBottom NSInteger section self numberOfSectionsInCo
  • 在 iOS 模拟器主屏幕或锁屏中设置壁纸(背景图像)

    当我正在绞尽脑汁思考某件事时 我的脑海中突然出现了这个想法 我们可以将模拟器的主屏幕背景图像设置为我们选择的图像吗 Xcode 3 2 2 模拟器 3 1 3 就是一个很好的例子 Certain versions of the simula
  • 如何在iPhone应用程序中的类结构中实现主键和外键表数据[关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 如何连接sqlite数据库中的两个表数据 if sqlite3 open dbPath UTF8String database SQL
  • 当用户到达 UITableView 的最后一行时,如何动态添加行?

    我有一个UITableview当前显示 10 行 固定为静态 现在我想在其中添加一个功能 当用户到达最后一行时 我想向表中添加更多 10 行UITableView 我的意思是目前我在应用程序中显示固定的 10 行 但现在我想在用户到达上一个
  • 允许的 APNS 持续连接数量是多少?

    我正在尝试编写服务器端代码来为我的应用程序发送推送通知 根据 Apple 的建议 我计划保留连接并根据需要发送推送通知 Apple 还允许打开和保留多个并行连接以发送推送通知 您可以与同一网关或多个网关实例建立多个并行连接 为此 我想维护一
  • 如何在 iOS 中查找蓝牙音频设备

    好的 我正在开发一个有趣的项目 该项目有一个障碍 我需要为我的 iOS 应用程序启用蓝牙音频支持 我遇到的障碍是我什至无法开始获取已连接的蓝牙音频设备的列表 即使我的 iPhone 5S 可以识别我的耳机 大约 3 4 岁的耳机 LG HB
  • 滑动删除不起作用

    滑动删除功能在我的表格视图中不起作用 我已经在导航栏中实现了 commitEditingStyle 委托和编辑按钮 因此 当用户单击编辑按钮时 删除和添加按钮会相应显示 但是 在滑动时 删除按钮不会出现 并且似乎它无法将滑动识别为对 set
  • iphone - 自动释放,没有池 - 只是泄漏

    我的主代码中有这一行 self performSelectorInBackground selector animateMe withObject nil 这是 animateMe void animateMe UIView animate
  • 您是否标记 UIView 或将它们保留为属性?

    这主要是一个风格问题 但自从我开始为 iPhone 编程以来 我一直很好奇其他人的想法是什么 当您的 iPhone 应用程序中有一个 UIView 并且需要在应用程序的其他位置访问它时 通常在视图控制器中的另一个函数中 您是否喜欢用整数标记
  • 是否有针对不同屏幕尺寸的单独故事板?

    基本上我已经完成了一个应用程序 我唯一的问题是 ATM 机应用程序在设计时只考虑了 4 英寸显示屏 当在 3 5 英寸模拟器上运行时 应用程序会丢失 0 5 英寸 显然 那么我的问题是 如何在 Xcode 5 中为不同的屏幕尺寸设置不同的故
  • 如何使用 iPhone SDK 实现可滑动的图像堆栈(例如照片应用程序)?

    我想获取一堆图像 或者可能是一组用于下载图像的 URL 并以全屏方式显示它们 一次一个 使用 iPhone SDK 使用用户滑动来平滑地为堆栈中的下一个图像设置动画 Apple 的 Photo app 似乎可以做到这一点 此外 如果尚未检索
  • XCode 无法将 iPhone 应用程序部署到 iPhone 3GS

    因此 我构建了我的 iPhone 应用程序 它在模拟器中运行良好 因此我想将其部署到我的 iPhone 上进行最后一轮测试 然后再使用我的分发配置文件进行公开 Beta 测试 我已经这样做过很多次了 从来没有出现过问题 然而 自从上次测试运
  • iPhone 的电子书框架

    我有一本书想作为 iPhone 应用程序发布 有谁知道我可以使用免费 或便宜 的框架来实现这一目标 换句话说 我想为我的书创建一个独立的 XCODE 项目 其中包含 iPhone 用户将本书作为独立应用程序阅读所需的所有代码 我见过 O R
  • 持久化 UINavigationItem 的 rightBarButtonItem 属性

    这可能是一个愚蠢的问题 但是有可能保持正确的吗 UIBarButtonItem跨由一个管理的多个视图UINavigationController 我的一系列观点通常具有相同的权利UIBarButtonItem 但是当我将新视图推送到我的UI
  • 导入 RNCryptor 后架构 armv7 的未定义符号

    我导入了 RNCryptor 可以在这里找到 https github com rnapier RNCryptor https github com rnapier RNCryptor进入我的应用程序 但是 我在日志中收到了三个错误 Und
  • 是否可以使用 Firebase 安排推送通知? [复制]

    这个问题在这里已经有答案了 我已经阅读了我能找到的所有文档 但仍然不知道这是否可行 如果我是用户 我可以安排特定时间的推送通知吗 Example 1 我是用户并打开应用程序 2 我允许通知并转到 pickerView 或其他任何内容 并设置
  • 虚拟乐器 iPhone 应用程序中的 VoiceOver 辅助功能?

    我收到盲人用户的评论 称我的一些声音和音乐相关应用程序只能在关闭 VoiceOver 的情况下使用 在 iOS 设备上启用 VoiceOver 辅助功能后 是否可以启用音乐键盘或鼓垫触摸区域 以便在点击键盘键或虚拟鼓组 等 时可以立即播放音
  • 如何在 iOS 8 中关闭两个 UIViewController?

    我正在使用 Objective C 开发 iPhone 应用程序 由于我需要一次关闭两个 UIViewController 所以我使用下面的代码 self presentingViewController presentingViewCon

随机推荐