我希望POST到图API的/ [event_id] / photos端点,以允许用户上传到他们的一个事件。该文档似乎可以上传本地文件附件,而不是指定互联网上已有图像的URL。
我正在使用react-native-fbsdk库,但我无法弄清楚如何上传照片。这就是我现在所拥有的:
sharePhotoToEvent: (eventId, imageUrl) => {
return new Promise((resolve, reject) => {
const eventsRequest = new GraphRequest(
`/${eventId}/photos`,
{
httpMethod: 'POST',
parameters: {
url: imageUrl
}
},
(error, result) => {
if (error) {
console.log('Event photo upload error:');
console.log(error);
reject(error);
} else if (result) {
console.log(result);
resolve(result);
} else {
reject();
}
}
);
// Start the graph request.
new GraphRequestManager().addRequest(eventsRequest).start();
});
}
imageUrl是保存在设备上的本地图像的文件路径。我是否需要使用与“url”不同的未记录参数?除了提供本地文件路径之外,还有其他一些步骤需要做吗?
本地文件路径的格式如下: 文件:///var/mobile/Containers/Data/Application/D3394FBD8-91E3-48B0-E32E-A1KDN831349E/Documents/mimi_image.jpg
以下是我收到的错误回复:
{ domain: 'com.facebook.sdk.core',
message: 'The operation couldn’t be completed. (com.facebook.sdk.core error 8.)',
userInfo:
{ NSRecoveryAttempter: null,
NSLocalizedRecoverySuggestion: 'The server is temporarily busy, please try again.',
'com.facebook.sdk:FBSDKGraphRequestErrorParsedJSONResponseKey':
{ code: 500,
body:
{ error:
{ type: 'OAuthException',
message: 'An unknown error has occurred.',
fbtrace_id: 'DE2PvnZlqm8',
code: 1 } } },
'com.facebook.sdk:FBSDKErrorDeveloperMessageKey': 'An unknown error has occurred.',
'com.facebook.sdk:FBSDKGraphRequestErrorHTTPStatusCodeKey': 500,
'com.facebook.sdk:FBSDKGraphRequestErrorGraphErrorCode': 1,
'com.facebook.sdk:FBSDKGraphRequestErrorCategoryKey': 1,
NSLocalizedRecoveryOptions: [ 'OK' ] },
nativeStackIOS:
[ '0 mimi 0x0000000100dd6148 RCTJSErrorFromCodeMessageAndNSError + 152',
'1 mimi 0x0000000100dd6070 RCTJSErrorFromNSError + 264',
'2 mimi 0x00000001010c8590 __48-[RCTFBSDKGraphRequestConnectionContainer start]_block_invoke + 156',
'3 mimi 0x0000000100b35c2c -[FBSDKGraphRequestMetadata invokeCompletionHandlerForConnection:withResults:error:] + 152',
'4 mimi 0x0000000100b3ca9c __82-[FBSDKGraphRequestConnection processResultBody:error:metadata:canNotifyDelegate:]_block_invoke + 160',
'5 mimi 0x0000000100b3c8e8 -[FBSDKGraphRequestConnection processResultBody:error:metadata:canNotifyDelegate:] + 956',
'6 mimi 0x0000000100b3e568 __76-[FBSDKGraphRequestConnection processorDidAttemptRecovery:didRecover:error:]_block_invoke + 64',
'7 mimi 0x0000000100b35c2c -[FBSDKGraphRequestMetadata invokeCompletionHandlerForConnection:withResults:error:] + 152',
'8 mimi 0x0000000100b3ca9c __82-[FBSDKGraphRequestConnection processResultBody:error:metadata:canNotifyDelegate:]_block_invoke + 160',
'9 mimi 0x0000000100b3c8e8 -[FBSDKGraphRequestConnection processResultBody:error:metadata:canNotifyDelegate:] + 956',
'10 mimi 0x0000000100b3c388 __64-[FBSDKGraphRequestConnection completeWithResults:networkError:]_block_invoke + 400',
'11 CoreFoundation 0x0000000181f9b988 <redacted> + 216',
'12 mimi 0x0000000100b3c124 -[FBSDKGraphRequestConnection completeWithResults:networkError:] + 556',
'13 mimi 0x0000000100b3b4f0 -[FBSDKGraphRequestConnection completeFBSDKURLSessionWithResponse:data:networkError:] + 1012',
'14 mimi 0x0000000100b39638 __36-[FBSDKGraphRequestConnection start]_block_invoke_2 + 80',
'15 libdispatch.dylib 0x0000000103b6d49c _dispatch_call_block_and_release + 24',
'16 libdispatch.dylib 0x0000000103b6d45c _dispatch_client_callout + 16',
'17 libdispatch.dylib 0x0000000103b72050 _dispatch_main_queue_callback_4CF + 1192',
'18 CoreFoundation 0x0000000182069eb0 <redacted> + 12',
'19 CoreFoundation 0x0000000182067a8c <redacted> + 2012',
'20 CoreFoundation 0x0000000181f87fb8 CFRunLoopRunSpecific + 436',
'21 GraphicsServices 0x0000000183e1ff84 GSEventRunModal + 100',
'22 UIKit 0x000000018b55c2e8 UIApplicationMain + 208',
'23 mimi 0x0000000100a5d3e4 main + 124',
'24 libdyld.dylib 0x0000000181aaa56c <redacted> + 4' ],
code: 'ECOM.FACEBOOK.SDK.CORE8' }