Facebook iOS上传视频“无法从访问令牌中检索会话密钥”。 [英] Facebook iOS Upload Video "Unable to retrieve session key from the access token."

查看:202
本文介绍了Facebook iOS上传视频“无法从访问令牌中检索会话密钥”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用ios-sdk在Facebook上上传视频

I want to upload video on facebook using ios-sdk

我查看有问题的讨论 iPhone Facebook视频上传,并尝试在我的应用程序中实现

I check discussion in question iPhone Facebook Video Upload and try to implement it in my application

我尝试你的代码,但没有成功

I try to your code but not succeed


  1. 我下载你的代码 https:// github .com / zoul / facebook-ios-sdk

  2. 从您的src添加FBVideoUpload.h / m类添加到我的项目中

  3. 在FBConnect.h


  4. 中包含FBVideoUpload.h,然后按如下方式上传视频代码

  1. I download your code https://github.com/zoul/facebook-ios-sdk
  2. take the FBVideoUpload.h/m classes from your src add add into my project
  3. include "FBVideoUpload.h" in FBConnect.h

  4. then I code for upload video as follow

这是代码

FBVideoUpload *upload = [[FBVideoUpload alloc] init];
upload.accessToken = facebookObj.accessToken;
upload.apiKey = fbAppKey;
upload.appSecret = fbAppSecret;
NSString *filePath = @"/Users/pratgupta/Library/Application Support/iPhone Simulator/4.1/Media/DCIM/100APPLE/IMG_0010.M4V";
NSURL *fileURL = [NSURL fileURLWithPath:filePath];
NSData *data = [NSData dataWithContentsOfFile:filePath];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                               data, @"",
                                               @"test", @"title",
                                               @"upload testing", @"description",
                                               @"EVERYONE", @"privacy",
                                               nil];
[upload startUploadWithURL:fileURL params:params delegate:self];

但是在日志中收到错误,即

无法从访问令牌

But got the error in Logs i.e
Unable to retrieve session key from the access token.

这是由于

if ([self sessionID] == nil) {
        NSLog(@"Unable to retrieve session key from the access token);
        return;
}

在类FBVideoUpload

in class FBVideoUpload

对于登录我正在使用此代码

For Login I am using this code

fbPermissions =  [[NSArray arrayWithObjects:
                       @"read_stream", @"offline_access", @"publish_stream",nil] retain];
facebookObj = [[Facebook alloc] initWithAppId:fbAppId];
[facebookObj authorize:fbPermissions delegate:self];

我可以从Facebook获取我的更新,所以会话在这里确定。

可以告诉我我在做什么错?

I am able to fetch my updates from facebook so then session is ok here.
Can you please tell me What wrong I am doing?

编辑

更改zoul建议的登录步骤后,我现在没有得到sessionID错误日志..我的请求现在发送到fb服务器,但得到这个响应

EDIT
After changing the login steps suggested by the zoul I am now not getting the sessionID error log.. My request is now sending to the fb server but getting this response

<?xml version="1.0" encoding="UTF-8"?>
<error_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">
  <error_code>100</error_code>
  <error_msg>privacy must contains a valid privacy 'value'</error_msg>
  <request_args list="true">
    <arg>
      <key>description</key>
      <value>upload testing</value>
    </arg>
    <arg>
      <key>privacy</key>
      <value>EVERYONE</value>
    </arg>
    <arg>
      <key>v</key>
      <value>1.0</value>
    </arg>
    <arg>
      <key>api_key</key>
      <value>[here is my API key]</value>
    </arg>
    <arg>
      <key>method</key>
      <value>facebook.video.upload</value>
    </arg>
    <arg>
      <key>session_key</key>
      <value>c4ada192feb82e8f239a283d-555042146</value>
    </arg>
    <arg>
      <key>sig</key>
      <value>8255d4cc3838b278b26fbfc8c86818a3</value>
    </arg>
    <arg>
      <key>title</key>
      <value>test</value>
    </arg>
  </request_args>
</error_response>

Amit Battan

推荐答案

请参阅 FBVideoUpload.h


请请注意,该代码从
的Facebook类解析
访问令牌,这是非常脆弱的,非官方的,
可以轻易地与即将发布的SDK版本相冲突。另外它
似乎只适用于较旧的弹出式验证和
不是使用应用程序切换的新的身份验证。 (新的身份验证
方案似乎导致不同的认证令牌格式
,我们无法解析。)

Please note that this code parses the access token from the Facebook class, which is quite brittle, unofficial and could easily break with the upcoming SDK releases. Also it seems to only work with the older, pop-up authentication and not the new one that uses app switching. (The new authentication scheme seems to result in a different auth token format that we can’t parse.)



你的问题看起来像是使用现代的应用交换认证方案。这导致不同的访问令牌,因此视频上传黑客不起作用。切换到较旧的身份验证方案很简单,请参阅此分支中的代码(它将 forceOldStyleAuth 属性添加到 Facebook 类)。

Your problem looks like you are using the modern, app-switching authentication scheme. That results in a different access token and therefore the video uploading hack does not work. Switching to the older authentication scheme is easy, see code in this branch (it adds a forceOldStyleAuth property to the Facebook class).

对于通过上传的字典,我的代码如下:

As for the dictionary to pass with the upload, here’s how my code looks:

NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
    @"Sample video title", @"title",
    @"Sample video description", @"description",
    nil];
upload = [[FBVideoUpload alloc] init];
[upload setApiKey:kAPIKey];
[upload setAccessToken:facebook.accessToken];
[upload setAppSecret:kAppSecret];
[upload startUploadWithURL:movieURL params:params delegate:self];

这对我有用。

这篇关于Facebook iOS上传视频“无法从访问令牌中检索会话密钥”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆