- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的这段代码到目前为止还无法发送 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
但是每次我运行它时,控制台都会显示以下内容:
{
"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
[ session 恢复]调用返回 TRUE。
提前致谢。
最佳答案
如果您使用最新的iOS SDK For Facebook然后使用下面的方法您可以将图像发布为流。
- (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 将不会发布。
关于iphone - FBConnect facebook.stream.publish 与 NSDictionary 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1652049/
我在使用以下代码来创建NSDictionaries的NSDictionary时遇到麻烦。没有编译错误,但是在运行时,此代码失败。 NSDictionary *section0 = [NSDiction
我得到了 '[NSDictionary]!? is not convertible to [NSDictionary]?' error on following code. var jsonRes
我有以下代码: NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; NSMutableDictionary *g
目前我有以下代码可以从 xml 文件中获取数据。这到目前为止有效 - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)el
在 Objective C 中,我们将字典值的 NSArray 分配给 NSDictionary 变量并获取键的值,如下所示,NSDictionary *dictValue = [array obje
将对象从一个 NSDictionary 复制到另一个 NSDictionary 的最简洁方法是什么?我必须从字典中提取特定值并将它们存储在新字典中。目前我有一些简单的代码,像这样...... NSSt
希望有人能帮助我: 我正在使用 NSDictionary 来填充 UITableView。它的模型类似于 [key:userID => value:userName]。tableView 只填充了 u
我有一本字典,其中包含从解析 JSON 中提取的其他字典中的子项。结构如下所示: { children = (
我需要检查 nsdictionary 中的元素是否不等于 normal,然后将该元素复制到一个数组中作为我的 UITable 的数据源。 这是一个条目的例子: Trailer = {
我正在尝试将数据添加到嵌套在其他词典中的 NSMutableDictionary。 在添加数据的代码运行之前开始输出 DayData Dictionary { //DayData
我的应用程序有一个 NSDictionary,其中包含许多其他 NSDictionary。如果我打印出这本词典,它的内容如下: oxip = { created = "2014-02-
我有一个 NSDictionary 记录这个: address = "30 East 23rd Street"; address1 = "30 East 23rd Street";
好的,我有一个 .plist 文件, 其中我有一个 NSDictionary *StoredAddresses, 在 StoredAddresses 中,是另一把 NSDictionary 我知道我可
您好,我在将数据从一个 NSDictionary 复制到另一个我使用的 NSDictionary 时遇到问题 [dicForFoodproduct_fromWeb initWithDictionary
我有一个包含四个对象的NSDictionary。每个对象都是一个包含数千个对象的 NSDictionary。我已经通过记录顶级字典的描述来验证它包含它应该包含的内容。但是,当我运行下面的代码以枚举该顶
给定的图像具有数据结构 我能够从 FirstText 和 LastText 获取数据,NSPredicate 是 subData.FirstText contains[cd] %@ OR subDat
我有一些装满书籍的 [NSDictionary],我正在检查这些书籍的值以便更好地在 UICollectionView 中显示内容。我正在检查一个 key 是否包含多个 ISBN 编号。如果是这样,我
我有一个很大的 NSDictionary,里面有一个较小的 NSDictionary。我想自动释放较大的一个,并保留第二个。我的初始化方法中有这段代码: // Autoreleased stage d
我对 Objective C 比较陌生。我有一个包含 NSDictionary 对象的 NSArray。我正在调用网络服务来获取数据。我有一个 PickerView,这是它的数据源(我实现了 numb
我想添加一个不同的字典作为另一个键字典的值,但在我的循环中,我发现相同的值添加到我所有的字典键。这是我的代码: for (MyObject *message in messages) {
我是一名优秀的程序员,十分优秀!