如何使用图表 API 将视频上传到我的 Facebook 页面?
How do I upload a video to my Facebook page using the graph API?
我一直在为如何解释获得的文档而苦苦挣扎here and here. I'm using Facebook's Javascript SDK。
async postVideo(page: IFacebookPage, videoFile: File): Promise<CreateAdResult> {
return new Promise<CreateAdResult>(async (resolve, reject) => {
try {
const data = new FormData()
data.append('source', videoFile)
const result = await this.post(`/${page.id}/videos`, page, { source: data })
resolve(result)
} catch (error) { reject(error) }
})
}
private async post(url: string, page: IFacebookPage, params: any): Promise<CreateAdResult> {
return new Promise<CreateAdResult>(async (resolve, reject) => {
const accessToken = await this.fetchFaceBookPageAccessToken(page.id)
this.FB().api(url, "post", { ...params, access_token: accessToken }, (response: any) => {
if (response && !response.error) {
resolve(CreateAdResult.PublishToFacebookSuccess)
} else {
const msg = response && response.error ? `Failed to post content to Facebook page with error: ${response.error.message} ` : `Failed to post ad to Facebook page!`
reject(Error(msg)) // <----- Ends up here!!
}
})
})
}
所有这些只会导致表单出现错误消息
Error: Failed to post content to Facebook page with error: There was a
problem uploading your video file. Please try again.
我通过将视频上传到其他地方并向 Facebook 提供 url 来解决这个问题。
即
async postVideo(page: IFacebookPage, videoUrl: string): Promise<CreateAdResult> {
return new Promise<CreateAdResult>(async (resolve, reject) => {
try {
const result = await this.post(`/${page.id}/videos`, page, { file_url: videoUrl })
resolve(result)
} catch (error) { reject(error) }
})
}
我一直在为如何解释获得的文档而苦苦挣扎here and here. I'm using Facebook's Javascript SDK。
async postVideo(page: IFacebookPage, videoFile: File): Promise<CreateAdResult> {
return new Promise<CreateAdResult>(async (resolve, reject) => {
try {
const data = new FormData()
data.append('source', videoFile)
const result = await this.post(`/${page.id}/videos`, page, { source: data })
resolve(result)
} catch (error) { reject(error) }
})
}
private async post(url: string, page: IFacebookPage, params: any): Promise<CreateAdResult> {
return new Promise<CreateAdResult>(async (resolve, reject) => {
const accessToken = await this.fetchFaceBookPageAccessToken(page.id)
this.FB().api(url, "post", { ...params, access_token: accessToken }, (response: any) => {
if (response && !response.error) {
resolve(CreateAdResult.PublishToFacebookSuccess)
} else {
const msg = response && response.error ? `Failed to post content to Facebook page with error: ${response.error.message} ` : `Failed to post ad to Facebook page!`
reject(Error(msg)) // <----- Ends up here!!
}
})
})
}
所有这些只会导致表单出现错误消息
Error: Failed to post content to Facebook page with error: There was a problem uploading your video file. Please try again.
我通过将视频上传到其他地方并向 Facebook 提供 url 来解决这个问题。
即
async postVideo(page: IFacebookPage, videoUrl: string): Promise<CreateAdResult> {
return new Promise<CreateAdResult>(async (resolve, reject) => {
try {
const result = await this.post(`/${page.id}/videos`, page, { file_url: videoUrl })
resolve(result)
} catch (error) { reject(error) }
})
}