-1

我想将 Vimeo 集成到我的应用程序中。我已经浏览了 vimeo开发者网站。一切都很好,但我无法进行身份验证。我已经完成了 Oauth 教程,但发现难以理解。我的截止日期很短。我发现这个链接但感觉并不容易和好。如果有人在它上面工作过,请指导我。

4

1 回答 1

1

起初我在我的项目中拖动了 OAuthConsumer 文件

http://oauth.googlecode.com/svn/code/obj-c/OAuthConsumer/

“Iphone ready”只是意味着您只需将文件添加到 Xcode,然后导入“OAuthConsumer.h”。

如果您正在使用 iPhone:

1)一定要添加Security.framework。

2) 在你的框架中包含 libxml2.dylib。您还需要在项目中添加一个构建属性——“标头搜索路径”需要包含“$SDKROOT/usr/include/libxml2”并选中“递归”。

在 Viewcontroller.h

#import "OAConsumer.h"
#import "OAMutableURLRequest.h"
#import "OADataFetcher.h"


@property(nonatomic,strong) OAToken  *accessToken;
@property(nonatomic,strong) IBOutlet UIWebView *webView;

在 Viewcontroller.m 中

@synthesize accessToken;
@synthesize webView;


- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.




// Do any additional setup after loading the view, typically from a nib.

OAConsumer *consumer = [[OAConsumer alloc] initWithKey:@"fa9374b9fc90f2ffd7b4P8K3776530fa6023985b"
                                                secret:@"d6242b63d435757526u87e7ceca98ffdcd8d9d55e"];

NSURL *url = [NSURL URLWithString:@"https://vimeo.com/oauth/request_token"];


OAMutableURLRequest *request = [[OAMutableURLRequest alloc] initWithURL:url
                                                               consumer:consumer
                                                                  token:nil
                                                                  realm:nil
                                                      signatureProvider:nil];

[request setParameters: [NSArray arrayWithObjects: [[OARequestParameter alloc] initWithName: @"oauth_callback" value: @"http://vimeo.com/api/rest/v2?format=json&method=vimeo.videos.search&qdfduery=amir+khan"] ,nil]];

[request setHTTPMethod:@"GET"];

OADataFetcher *fetcher = [[OADataFetcher alloc] init];

[fetcher fetchDataWithRequest:request

                     delegate:self

            didFinishSelector:@selector(requestTokenTicket:didFinishWithData:)

              didFailSelector:nil];


}




- (void)requestTokenTicket:(OAServiceTicket *)ticket didFinishWithData:(NSData *)data {
if (ticket.didSucceed)
{




    NSString *responseBody = [[NSString alloc] initWithData:data
                                                   encoding:NSUTF8StringEncoding];
    OAToken *requestToken = [[OAToken alloc] initWithHTTPResponseBody:responseBody];
    NSLog(@"data %@",requestToken);

    OAMutableURLRequest *request;

    if (self.accessToken != nil)
    {
        self.accessToken = nil;
    }

    self.accessToken = [[OAToken alloc] initWithHTTPResponseBody:responseBody];
    NSLog(@"access token key %@",self.accessToken.key) ;
    NSLog(@"access token secret %@",self.accessToken.secret) ;
    NSURL *url = [NSURL URLWithString:@"https://vimeo.com/oauth/authorize"];
    OAConsumer *consumer = [[OAConsumer alloc] initWithKey:self.accessToken.key
                                                    secret:self.accessToken.secret];

    request = [[OAMutableURLRequest alloc] initWithURL:url
                                              consumer:consumer
                                                 token:self.accessToken
                                                 realm:nil
                                     signatureProvider:nil];

    OARequestParameter *p0 = [[OARequestParameter alloc] initWithName:@"oauth_token" value:self.accessToken.key];
    NSArray *params = [NSArray arrayWithObject:p0];
    [request setParameters:params];
    [webView loadRequest:request];
    NSLog(@"request %@",request);



   }
}
于 2013-09-04T13:33:17.700 回答