Downalod Facebook GraphApi from And Add it in your Project.Place This code to Share Video in facebook
- (void)viewDidLoad
{
facebook = [[Facebook alloc] initWithAppId:@"Replace With Your AppID"];
}
- (void)storeAuthData:(NSString *)accessToken expiresAt:(NSDate *)expiresAt {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:accessToken forKey:@"FBAccessTokenKey"];
[defaults setObject:expiresAt forKey:@"FBExpirationDateKey"];
[defaults synchronize];
}
- (IBAction)buttonClicked:(id)sender {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"] && [defaultsobjectForKey:@"FBExpirationDateKey"]) {
facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
}
if (![facebook isSessionValid]) {
NSArray * permissions = [NSArray arrayWithObjects:@"read_stream",@"offline_access", @"email", nil];
[facebook authorize:permissions delegate:self];
}
if ([facebook isSessionValid]) {
//Replace Filepath With your file
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"sample"ofType:@"mov"];
NSData *videoData = [NSData dataWithContentsOfFile:filePath];
NSMutableDictionary *params = [NSMutableDictionarydictionaryWithObjectsAndKeys:
videoData, @"video.mov",
@"video/quicktime", @"contentType",
@"Video Test Title", @"title",
@"Video Test Description", @"description",
nil];
[facebook requestWithGraphPath:@"me/videos"
andParams:params
andHttpMethod:@"POST"
andDelegate:self];
}
}
- (void)fbDidLogin {
[self storeAuthData:[facebook accessToken] expiresAt:[facebook expirationDate]];
if ([facebook isSessionValid]) {
NSLog(@"????? Mahesh babu");
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"sample"ofType:@"mov"];
NSData *videoData = [NSData dataWithContentsOfFile:filePath];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
videoData, @"video.mov",
@"video/quicktime", @"contentType",
@"Video Test Title", @"title",
@"Video Test Description", @"description",
nil];
[facebook requestWithGraphPath:@"me/videos"
andParams:params
andHttpMethod:@"POST"
andDelegate:self];
}
}
-(void)fbDidNotLogin:(BOOL)cancelled {
NSLog(@"did not login");
}
- (void)request:(FBRequest *)request didLoad:(id)result {
if ([result isKindOfClass:[NSArray class]]) {
result = [result objectAtIndex:0];
}
NSLog(@"Result of API call: %@", result);
}
- (void)request:(FBRequest *)request didFailWithError:(NSError *)error {
NSLog(@"Failed with error: %@", [error localizedDescription]);
}
Note : It is necessary to add both fbconnect api and graph api.
No comments:
Post a Comment