1

I want to upload video on facebook using ios-sdk

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. 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

This is Code

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.

which is due to

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

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];

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?

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

Community
  • 1
  • 1
Amit Battan
  • 2,968
  • 2
  • 32
  • 68

2 Answers2

3

The privacy dictionary entry format changed:

  NSDictionary * params = [NSDictionary dictionaryWithObjectsAndKeys:
                          @"Sample video title", @"title",
                          @"Sample video description", @"description",
                          @"{\"value\": \"ALL_FRIENDS\"}", @"privacy",
                          nil];

The Graph API docs for the Post object talk about the privacy object: http://developers.facebook.com/docs/reference/api/post/

But that doesn't fix the video not showing up in "My Videos" or even allow my friends to see it if they have the direct link. The Share button on the video page is broken too, so I can't even get it posted to my wall that way.

Christina
  • 795
  • 7
  • 9
  • yes privacy issue is solved now.. but very surprising why video still not showing http://stackoverflow.com/questions/5565512/ – Amit Battan Apr 07 '11 at 05:24
  • 1
    I had the same video issue you did yesterday but it's working now. Maybe something was wonky with facebook's servers. – Christina Apr 07 '11 at 18:09
1

See the comments in FBVideoUpload.h:

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.)

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];

This works for me.

zoul
  • 102,279
  • 44
  • 260
  • 354
  • Yes. (And obviously you’ll have to merge the code from the mentioned branch first, otherwise there’s no `forceOldStyleAuth` to begin with.) – zoul Apr 05 '11 at 14:00
  • Now error log is not coming But video is not uploaded .... I am getting successful response but when check facebook not found any video uploaded here . . . . . **response receive in the logs** `received response..http://api-video.facebook.com/restserver.php ` – Amit Battan Apr 05 '11 at 14:02
  • 1
    Read the discussion under the [original question](http://stackoverflow.com/questions/5355846), you might have problems with the application type. – zoul Apr 05 '11 at 14:52
  • my application already set as `HTML 5 / mobile web` type , even I try to toggle to as Native App .. but not works in any way . . . . http://i.imgur.com/TCDVt.png – Amit Battan Apr 06 '11 at 05:55
  • @zoul I have edit the question and add the response which I am getting `privacy must contains a valid privacy 'value'` – Amit Battan Apr 06 '11 at 06:28
  • How about leaving out the privacy line alltogether? I don’t think I have anything like that in my working code. – zoul Apr 06 '11 at 06:34
  • I have use the code which I posted ,.. and in core fb-sdk code I have not change any thing else except your suggestion about forceOldStyleAuth – Amit Battan Apr 06 '11 at 06:44
  • What I am suggesting is that you delete the privacy/EVERYONE line from the dictionary that you pass along with the video. – zoul Apr 06 '11 at 06:54
  • No No zoul I have not delete the `privacy/EVERYONE` .. I just change in facebook.h/m file related to `forceOldStyleAuth` nothing else and ` @"EVERYONE", @"privacy"` is in my code – Amit Battan Apr 06 '11 at 07:09
  • 1
    Yes :) And because the server does not like the privacy settings, you should try to delete that line and see if the upload succeeds. – zoul Apr 06 '11 at 07:17
  • Well Now I am getting this error .. `Video file was corrupt or invalid` try to upload with other video . . Now privacy is a issue here – Amit Battan Apr 06 '11 at 07:45
  • 1
    The dictionary you are passing along with the video might be wrong. I’ll update the answer with the dictionary I use in my code. – zoul Apr 06 '11 at 07:51
  • Well thanks zoul .. video uploaded successfully .. But its not shown in my videos .. when I open the given in response then I got the video but When I go **Back To My Videos** then not able to see the video and even not able to shown in my profile wall . . . http://i.imgur.com/8jH0B.png -> http://i.imgur.com/pTLZN.png – Amit Battan Apr 06 '11 at 08:06
  • Well ... Thanks for your help zoul .. if got any idea please post – Amit Battan Apr 06 '11 at 08:57
  • May be this issue also due to privacy – Amit Battan Apr 06 '11 at 09:19
  • As Christina suggest privacy issue parameter issue is solved ... but still not showing video in profile .. and some other also report as in link http://forum.developers.facebook.net/viewtopic.php?id=95366 .. in there code it was working but not it is not .. then may be FB has done some change in API – Amit Battan Apr 07 '11 at 12:38