当尝试使用应用范围用户id通过Facebook iOS图形API获取用户照片时,应用程序崩溃

当尝试使用应用范围用户id通过Facebook iOS图形API获取用户照片时,应用程序崩溃,ios,facebook,facebook-graph-api,Ios,Facebook,Facebook Graph Api,我在iOS上使用Facebook。我通过Graph Api毫无问题地获取用户数据。从用户的数据中,我获取应用程序范围内的用户id。然后我尝试获取用户的图片,但应用程序崩溃。我尝试使用[FBRequestConnection startWithGraph:@”/me/picture…]和[FBRequestConnection startWithGraph:@/(来自用户数据的应用程序id)/picture…],但仍然崩溃。为什么? 2014-06-02 16:16:51.669 testa

我在iOS上使用Facebook。我通过Graph Api毫无问题地获取用户数据。从用户的数据中,我获取应用程序范围内的用户id。然后我尝试获取用户的图片,但应用程序崩溃。我尝试使用[FBRequestConnection startWithGraph:@”/me/picture…]和[FBRequestConnection startWithGraph:@/(来自用户数据的应用程序id)/picture…],但仍然崩溃。为什么?

   2014-06-02 16:16:51.669 testapp[448:60b] -[NSNull dataUsingEncoding:]: unrecognized selector sent to instance 0x19f8068

   2014-06-02 16:16:51.679 testapp[448:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull dataUsingEncoding:]: unrecognized selector sent to instance 0x19f8068'

   *** First throw call stack:

(
    0   CoreFoundation                      0x018ac1e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x0162b8e5 objc_exception_throw + 44
    2   CoreFoundation                      0x01949243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
    3   CoreFoundation                      0x0189c50b ___forwarding___ + 1019
    4   CoreFoundation                      0x0189c0ee _CF_forwarding_prep_0 + 14
    5   testapp                             0x00022721 +[FBUtility simpleJSONDecode:error:] + 42
    6   testapp                             0x0000a75e -[FBRequestConnection parseJSONOrOtherwise:error:] + 69
    7   testapp                             0x0000a5a0 -[FBRequestConnection parseJSONResponse:error:statusCode:] + 1256
    8   testapp                             0x00009e04 -[FBRequestConnection completeWithResponse:data:orError:] + 666
    9   testapp                             0x00007564 __68-[FBRequestConnection startWithCacheIdentity:skipRoundtripIfCached:]_block_invoke + 201
    10  testapp                             0x00045fbc -[FBURLConnection invokeHandler:error:response:responseData:] + 49
    11  testapp                             0x00045ec7 -[FBURLConnection logAndInvokeHandler:response:responseData:] + 414
    12  testapp                             0x00046442 -[FBURLConnection connectionDidFinishLoading:] + 248
    13  Foundation                          0x013f4e49 ___NSURLConnectionDidFinishLoading_block_invoke + 40
    14  Foundation                          0x0138b7e1 __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke + 62
    15  Foundation                          0x01213f5e -[NSURLConnectionInternalConnection invokeForDelegate:] + 119
    16  Foundation                          0x01213ec6 -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 208
    17  Foundation                          0x01213dd8 -[NSURLConnectionInternal _withActiveConnectionAndDelegate:] + 76
    18  Foundation                          0x01214188 _NSURLConnectionDidFinishLoading + 43
    19  CFNetwork                           0x064aa69f ___ZN27URLConnectionClient_Classic26_delegate_didFinishLoadingEU13block_pointerFvvE_block_invoke + 111
    20  CFNetwork                           0x064a83de ___ZN27URLConnectionClient_Classic18_withDelegateAsyncEPKcU13block_pointerFvP16_CFURLConnectionPK33CFURLConnectionClientCurrent_VMaxE_block_invoke_2 + 104
    21  CoreFoundation                      0x0184dc69 CFArrayApplyFunction + 57
    22  CFNetwork                           0x06411441 _ZN19RunloopBlockContext7performEv + 155
    23  CFNetwork                           0x064f33f4 _ZThn16_N19RunloopBlockContext24multiplexerClientPerformEv + 20
    24  CFNetwork                           0x06411257 _ZN17MultiplexerSource7performEv + 299
    25  CFNetwork                           0x0641106c _ZN17MultiplexerSource8_performEPv + 76
    26  CoreFoundation                      0x0183577f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    27  CoreFoundation                      0x0183510b __CFRunLoopDoSources0 + 235
    28  CoreFoundation                      0x018521ae __CFRunLoopRun + 910
    29  CoreFoundation                      0x018519d3 CFRunLoopRunSpecific + 467
    30  CoreFoundation                      0x018517eb CFRunLoopRunInMode + 123
    31  GraphicsServices                    0x038a05ee GSEventRunModal + 192
    32  GraphicsServices                    0x038a042b GSEventRun + 104
    33  UIKit                               0x002ebf9b UIApplicationMain + 1225
    34  testapp                             0x00003b2d main + 141
    35  libdyld.dylib                       0x01ef3701 start + 1
    36  ???                                 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

谢谢

我想这是因为如果你查询
/me/picture
,你没有处理Facebook发送的http重定向。如果您只需要图片的URL,请按照文档中的说明使用
/me/picture?redirect=false


否则,添加一些代码来处理http重定向。

我解决了我的问题。我发送重定向参数,比如Bool。当我更改为字符串时,它开始工作


谢谢。

您需要提供崩溃代码、错误消息和回溯。获取有关异常的更多信息,请添加异常断点。转到“断点导航器”,单击左下角的“+”,选择“添加异常断点”。运行应用程序以获取断点。当您遇到异常断点时,单击调试继续几次,您将得到一个回溯和更多错误信息。发布该消息和Xcode/Debugger消息的精确副本。出于好奇,它是什么类型的重定向?Meta还是http 301?我从上面粘贴的错误中看到一个304 Not Modified(),您可以看到您的应用程序无法解析结果。这是因为在
/me/picture
的情况下,不会得到JSON,而是HTTP重定向。您可以通过添加访问令牌来尝试:{Access_Token}我没有获取JSON,因为我使用[FBRequestConnection startWithGraphPath:@”/me/picture“参数:param HTTPMethod:@“get”completionHandler:^(FBRequestConnection*连接,id结果,NSError*错误){…}从iOS Facebook.frameworkI修复了崩溃。我通过NSDictionary*param=[NSDictionary Dictionary WithObjectsAndKeys:NO,@“redirect”,nil]生成了参数;我将NO更改为“false”,它就可以工作了。谢谢!