Iphone 通过iOS 6应用程序在facebook上以编程方式共享视频?
我正在开发一个应用程序,需要在Facebook上共享视频。当我尝试developer.facebook.com寻找解决方案时,我找到了。它通过图形API共享视频。graph API是否在iOS 6中工作?请建议。如果有,请提供任何示例代码Iphone 通过iOS 6应用程序在facebook上以编程方式共享视频?,iphone,ios,facebook,video,Iphone,Ios,Facebook,Video,我正在开发一个应用程序,需要在Facebook上共享视频。当我尝试developer.facebook.com寻找解决方案时,我找到了。它通过图形API共享视频。graph API是否在iOS 6中工作?请建议。如果有,请提供任何示例代码 提前感谢。是的,你可以做到这一点,Facebook刚刚发布了新的框架3.5,它将轻松适用于iOS5和iOS6试试我使用的Facebook SDK 3.1 .h文件 #import <FacebookSDK/FacebookSDK.h>
提前感谢。是的,你可以做到这一点,Facebook刚刚发布了新的框架3.5,它将轻松适用于iOS5和iOS6试试我使用的Facebook SDK 3.1 .h文件
#import <FacebookSDK/FacebookSDK.h>
extern NSString *const SCSessionStateChangedNotificationCamera;
#导入
外部NSString*常量SCSessionStateChangedNotificationCamera;
.m文件
NSString *const SCSessionStateChangedNotificationCamera = @"com.facebook.Scrumptious:SCSessionStateChangedNotification";
-(IBAction)btnFacebookShareClick:(id)sender {
if (![self openSessionWithAllowLoginUI:YES]) {
[self showLoginView];
}
}
#pragma mark -
#pragma mark - Facebook Method
- (void) performPublishAction:(void (^)(void)) action {
if ([FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound) {
[FBSession.activeSession reauthorizeWithPublishPermissions:[NSArray arrayWithObject:@"publish_actions"] defaultAudience:FBSessionDefaultAudienceFriends completionHandler:^(FBSession *session, NSError *error) {
if (!error) {
action();
}
}];
}
else {
action();
}
}
#pragma mark -
#pragma mark Facebook Login Code
- (void)showLoginView {
[self dismissViewControllerAnimated:NO completion:nil];
[self performSelector:@selector(showLoginView1) withObject:nil afterDelay:1.5f];
}
- (void)showLoginView1 {
}
- (void)sessionStateChanged:(FBSession *)session state:(FBSessionState)state error:(NSError *)error {
switch (state) {
case FBSessionStateOpen: {
if (self != nil) {
[[FBRequest requestForMe] startWithCompletionHandler: ^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (error) {
//error
}else{
if ([FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound) {
NSArray *permissions = [[NSArray alloc] initWithObjects: @"publish_actions", @"publish_stream", nil];
[FBSession.activeSession reauthorizeWithPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceFriends completionHandler:^(FBSession *session, NSError *error) {
if (!error) {
[self uploadVideoOnFacebook];
}
else {
NSLog(@"%@",error);
}
}];
}
else {
[self uploadVideoOnFacebook];
}
}
}];
}
FBCacheDescriptor *cacheDescriptor = [FBFriendPickerViewController cacheDescriptor];
[cacheDescriptor prefetchAndCacheForSession:session];
}
break;
case FBSessionStateClosed: {
[self StopSpinner];
UIViewController *topViewController = [self.navigationController topViewController];
UIViewController *modalViewController = [topViewController modalViewController];
if (modalViewController != nil) {
[topViewController dismissViewControllerAnimated:YES completion:nil];
}
//[self.navigationController popToRootViewControllerAnimated:NO];
[FBSession.activeSession closeAndClearTokenInformation];
[self performSelector:@selector(showLoginView) withObject:nil afterDelay:0.5f];
}
break;
case FBSessionStateClosedLoginFailed: {
[self StopSpinner];
[self performSelector:@selector(showLoginView) withObject:nil afterDelay:0.5f];
}
break;
default:
break;
}
[[NSNotificationCenter defaultCenter] postNotificationName:SCSessionStateChangedNotificationCamera object:session];
if (error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"Error: %@", [CameraViewController FBErrorCodeDescription:error.code]] message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
[alertView release];
}
}
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
NSArray *permissions = [[NSArray alloc] initWithObjects: @"publish_actions", @"publish_stream", nil];
return [FBSession openActiveSessionWithPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceFriends allowLoginUI:allowLoginUI completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
if (!error) {
[self sessionStateChanged:session state:state error:error];
}
else {
NSLog(@"%@",error);
}
}];
}
+ (NSString *)FBErrorCodeDescription:(FBErrorCode) code {
switch(code){
case FBErrorInvalid :{
return @"FBErrorInvalid";
}
case FBErrorOperationCancelled:{
return @"FBErrorOperationCancelled";
}
case FBErrorLoginFailedOrCancelled:{
return @"FBErrorLoginFailedOrCancelled";
}
case FBErrorRequestConnectionApi:{
return @"FBErrorRequestConnectionApi";
}case FBErrorProtocolMismatch:{
return @"FBErrorProtocolMismatch";
}
case FBErrorHTTPError:{
return @"FBErrorHTTPError";
}
case FBErrorNonTextMimeTypeReturned:{
return @"FBErrorNonTextMimeTypeReturned";
}
case FBErrorNativeDialog:{
return @"FBErrorNativeDialog";
}
default:
return @"[Unknown]";
}
}
-(void) uploadVideoOnFacebook {
NSURL *pathURL;
NSData *videoData;
pathURL = [NSURL URLWithString:self.strUploadVideoURL];
videoData = [NSData dataWithContentsOfURL:[NSURL URLWithString:self.strUploadVideoURL]];
NSString *strDesc;
strDesc = txtCaption.text;
NSDictionary *videoObject = @{@"title": @"application Name",@"description": strDesc,[pathURL absoluteString]: videoData};
FBRequest *uploadRequest = [FBRequest requestWithGraphPath:@"me/videos" parameters:videoObject HTTPMethod:@"POST"];
[self.view setUserInteractionEnabled:NO];
[uploadRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error)
[AJNotificationView showNoticeInView:self.view type:AJNotificationTypeGreen title:@"Video uploaded successfully" linedBackground:AJLinedBackgroundTypeAnimated hideAfter:3.0];
else
[AJNotificationView showNoticeInView:self.view type:AJNotificationTypeRed title:@"Video uploaded error" linedBackground:AJLinedBackgroundTypeAnimated hideAfter:3.0];
[NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(popViewAfterMKInfo) userInfo:nil repeats:NO];
}];
}
NSString*const SCSessionStateChangedNotificationCamera=@“com.facebook.scrumpious:SCSessionStateChangedNotification”;
-(iAction)btnFacebookShareClick:(id)发件人{
如果(![self-openSessionWithAllowLoginUI:是]){
[自我展示登录视图];
}
}
#布拉格标记-
#pragma-mark-Facebook方法
-(作废)执行公告:(作废)(作废)行为{
if([FBSession.activeSession.permissions indexOfObject:@“发布操作”]==NSNotFound){
[FBSession.activeSession reauthorizeWithPublishPermissions:[NSArray arrayWithObject:@“publish_actions”]默认访问群体:FBSessionDefaultAudienceFriends completionHandler:^(FBSession*会话,NSError*错误){
如果(!错误){
动作();
}
}];
}
否则{
动作();
}
}
#布拉格标记-
#pragma标记Facebook登录代码
-(无效)showLoginView{
[自我解除视图控制器激活:未完成:无];
[自执行选择器:@selector(showLoginView1),对象:nil afterDelay:1.5f];
}
-(无效)ShowLoginView 1{
}
-(void)会话状态已更改:(FBSession*)会话状态:(FBSessionState)状态错误:(NSError*)错误{
开关(状态){
案例FBSessionStateOpen:{
if(self!=nil){
[[FBRequest requestForMe]startWithCompletionHandler:^(FBRequestConnection*连接,NSDictionary*用户,NSError*错误){
如果(错误){
//错误
}否则{
if([FBSession.activeSession.permissions indexOfObject:@“发布操作”]==NSNotFound){
NSArray*权限=[[NSArray alloc]initWithObjects:@“发布操作”,“发布流”,无];
[FBSession.activeSession重新授权WithPublishPermissions:权限默认访问群体:FBSessionDefaultAudienceFriends completionHandler:^(FBSession*会话,NSError*错误){
如果(!错误){
[自上传视频到Facebook];
}
否则{
NSLog(@“%@”,错误);
}
}];
}
否则{
[自上传视频到Facebook];
}
}
}];
}
FBCacheDescriptor*cacheDescriptor=[FBFriendPickerViewController cacheDescriptor];
[缓存描述符预取和缓存会话:会话];
}
打破
案件审理结束:{
[自动停止旋转器];
UIViewController*topViewController=[self.navigationController topViewController];
UIViewController*modalViewController=[topViewController modalViewController];
if(modalViewController!=nil){
[topViewController解除ViewController激活:是完成:无];
}
//[self.navigationController-popToRootViewControllerAnimated:NO];
[FBSession.activeSession closeAndClearTokenInformation];
[自执行选择器:@selector(showLoginView),对象:nil afterDelay:0.5f];
}
打破
案例FBSessionStateClosedLogin失败:{
[自动停止旋转器];
[自执行选择器:@selector(showLoginView),对象:nil afterDelay:0.5f];
}
打破
违约:
打破
}
[[NSNotificationCenter defaultCenter]postNotificationName:SCSessionStateChangedNotificationCamera对象:会话];
如果(错误){
UIAlertView*alertView=[[UIAlertView alloc]initWithTitle:[NSString stringWithFormat:@“错误:%@,[CameraViewController FBErrorCodeDescription:错误.代码]]消息:错误.本地化描述委托:nil取消按钮提示:@“确定”其他按钮提示:nil];
[警报视图显示];
[警报视图发布];
}
}
-(BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI{
NSArray*权限=[[NSArray alloc]initWithObjects:@“发布操作”,“发布流”,无];
返回[FBSession openActiveSessionWithPublishPermissions:权限默认访问群体:FBSessionDefaultAudienceFriends allowLoginUI:allowLoginUI completionHandler:^(FBSession*会话,FBSessionState,NSError*错误){
如果(!错误){
[自会话状态已更改:会话状态:状态错误:错误];
}
否则{
NSLog(@“%@”,错误);
}
}];
}
+(NSString*)FBErrorCodeDescription:(FBErrorCode)代码{
开关(代码){
案例FBErrorInvalid:{
返回@“FBErrorInvalid”;
}
案例FBErrorOperation已取消:{
返回@“FBErrorOperationCancelled”;
}
案例FBErrorLogin失败或取消:{
返回@“FBErrorLoginFailedOrCancelled”;
}
案例FBErrorRequestConnectionApi:{
返回@“FBErrorRequestConnectionApi”;