Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
雅虎,;从iOS获取配置文件详细信息_Ios_Objective C_Yahoo Api - Fatal编程技术网

雅虎,;从iOS获取配置文件详细信息

雅虎,;从iOS获取配置文件详细信息,ios,objective-c,yahoo-api,Ios,Objective C,Yahoo Api,我在这里列出了我遵循的雅虎整合步骤 第一步。我去了 第二步。从此处下载整个框架- 第三步。我确实将该框架拖放到了我的项目中 第四步。yahoo框架文件的启用标志fno objc arc 第五步。我在viewController的头文件中导入了“YOSSocial.h” 第六步。在view Dod load中,我放置了代码块1,以创建会话对象 第七步。单击一个按钮,我调用,代码块2 第八步。在AppDelegate.m中,我将方法实现为代码块3 第九步。我在重定向中接收到oauth\u令牌和oa

我在这里列出了我遵循的雅虎整合步骤

  • 第一步。我去了
  • 第二步。从此处下载整个框架-
  • 第三步。我确实将该框架拖放到了我的项目中
  • 第四步。yahoo框架文件的启用标志
    fno objc arc
  • 第五步。我在viewController的头文件中导入了“YOSSocial.h”
  • 第六步。在view Dod load中,我放置了代码块1,以创建会话对象
  • 第七步。单击一个按钮,我调用,代码块2
  • 第八步。在AppDelegate.m中,我将方法实现为代码块3
  • 第九步。我在重定向中接收到
    oauth\u令牌
    oauth\u验证器
代码块1

 - (void)viewDidLoad {
    [super viewDidLoad];
    self.session = [YOSSession sessionWithConsumerKey:@"ConsumerKeyHere"
                                           andConsumerSecret:@"ConsumerSecretKeyHere"
                                            andApplicationId:@"AppKey"];
    BOOL hasSession = [self.session resumeSession];
    if(hasSession == FALSE) {
        // custom call back URL which will redirect to our-app.
        // 10.0.0.76/iOS/callback.php redirects 
        // to com.mymobileapps.currentApp.yahoo
        [self.session 
           sendUserToAuthorizationWithCallbackUrl:
           @"http://10.0.0.76/iOS/callback.php"];
    } else {
        [self sendRequests];
    }
}
- (IBAction)connectYahoo:(id)sender {
      [[UIApplication sharedApplication] 
           openURL:[NSURL URLWithString:
           @"http://yourLocalServer/iOS/yos-social-php-master/sample/sampleapp.php"
      ]];
}
代码块2

- (void)sendRequests {
    // initialize a user request for the logged-in user
    YOSUserRequest *request = [YOSUserRequest requestWithSession:self.session];

    // fetch the user's profile data
    [request fetchProfileWithDelegate:self];
}

- (void)requestDidFinishLoading:(YOSResponseData *)data {
    // parse the response text string into a dictionary
    NSDictionary *rspData = [NSJSONSerialization JSONObjectWithData:[data.responseText dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments error:nil];
    NSDictionary *profileData = [rspData objectForKey:@"profile"];

    // format a string using the nickname object from the profile.
    NSString *welcomeText = [NSString stringWithFormat:@"Hey %@ %@!",
                             [profileData objectForKey:@"givenName"],
                             [profileData objectForKey:@"familyName"]];
    NSLog(@"welcometext is %@",welcomeText);
    self.lblProfile.text = welcomeText;
}
- (BOOL)application:(UIApplication *)application
        openURL:(NSURL *)url
   sourceApplication:(NSString *)sourceApplication
     annotation:(id)annotation {

    if([[url scheme] isEqualToString:@"com.yourcompany.app.fsq"]) {
        return [self.obj_LoginHomeVCtr.foursquare handleOpenURL:url];
    } else if([[url scheme] isEqualToString:@"com.yourcompany.app.googleplus"]){
        return [GPPURLHandler handleURL:url
                  sourceApplication:sourceApplication
                         annotation:annotation];

    }else if([[url scheme] isEqualToString:@"fb188315544652080"]){
        return [FBAppCall handleOpenURL:url
                  sourceApplication:sourceApplication
                    fallbackHandler:^(FBAppCall *call) {
                        NSLog(@"In fallback handler");
                    }];
    } else if ([[url scheme] isEqualToString:@"com.yourcompany.app.yahoo"]){
        STLog(@"URL is %@",url);
        return YES;
    }
    return YES;
}
代码块3

- (BOOL)application: (UIApplication *)application
            openURL: (NSURL *)url
  sourceApplication: (NSString *)sourceApplication
         annotation: (id)annotation {
    NSString *str = [[url description] stringByReplacingOccurrencesOfString:@"com.mymobileapps.currentApp.yahoo://oauth-response?oauth_token=" withString:@""];
    NSArray *ar = [str componentsSeparatedByString:@"&oauth_verifier="];
    NSLog(@"oauth_token is %@",[ar objectAtIndex:0]);
    NSLog(@"oauth_verifier is %@",[ar objectAtIndex:1]);
    // How my session will get updated now with valid authentication done?
    return YES;
}
<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLName</key>
        <string>com.yourcompany.app.yahoo</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>com.yourcompany.app.yahoo</string>
        </array>
    </dict>
</array>
我按照此处所述的每个步骤进行操作-&我还按照此处所述实现了重定向-

问题如下。 我仍然无法获取用户配置文件的详细信息,如性别、出生日期等。也就是说,从代码块2,我收到的数据为零

检索用户配置文件数据的代码中缺少什么?

其他参考资料

- (BOOL)application: (UIApplication *)application
            openURL: (NSURL *)url
  sourceApplication: (NSString *)sourceApplication
         annotation: (id)annotation {
    return [GPPURLHandler handleURL:url
                  sourceApplication:sourceApplication
                         annotation:annotation];
}
上面的代码说明了Google+框架如何处理重定向和管理本地会话。就雅虎而言,我没有发现任何有助于更新移动应用程序本地会话的详细信息

编辑:

如果无法通过Yahoo OAuth获取基本的个人资料(如性别、出生日期、电子邮件ID、姓名等)如何从Yahoo获取基本的个人资料信息?

从您在此处链接的Yahoo文档中,有几点需要检查:

  • 检查您是否正在请求并收到用户对正确权限的批准

  • 检查
    YOSResponseData
    对象,如果发生错误,它应该包含
    NSError
    对象

  • 它还包含一个
    NSHTTPURLResponse
    对象。检查响应标题和状态代码


您可能已经检查过这些内容,如果是,请将结果添加到问题中

fetchProfileWithDelegate:
()构建一个URL并设置一些头信息,然后将此数据传递给
[YOSRequestClient-sendAsyncRequestWithDelegate:][/code>()

然后,请求客户端创建一个
NSMutableURLRequest
NSURLConnection
并启动一个连接

下载数据后(如果有)
YoseResponseData
将接管并从下载的数据中创建一个新对象()

我看不到允许传入的
serviceressedata
对象为
nil
的代码路径。您至少应该能够看到
[数据成功]
,这将告诉您HTTP响应是否为
<400
。奇怪的是,如果服务器只是在没有HTTP响应的情况下打开和关闭连接,我相信
[data didcessfuel]==YES
,尽管它显然没有成功(因为0<400)

看起来你没有做错什么。我的猜测是,从那时起,该公司经历了重大重组,该项目已经被放弃,没有人费心记录下来

更新:除了4年没有更新外,雅虎的。我认为雅虎针对该软件的API不再有效了

这是解决方案

注意:您需要一个中间服务器

  • 步骤01。下载PHP雅虎框架
  • 步骤02。启动WAMP/XAMPP服务器
  • 步骤03。获取URL
    • 示例-
      http://10.0.0.76/iOS/yos-social-php-master/sample/sampleapp.php
  • 步骤04。返回XCode项目
  • 步骤05。打开XIB,为Yahoo&connect iAction方法放置一个按钮
  • 步骤06。在iAction方法中,导航到从iOS应用程序到URL的已获取URL。请参见代码块1
  • 步骤07。在AppDelegate.m中添加方法,用于处理从服务器到移动应用的重定向。请参见代码块2
  • 步骤08。确保您的应用程序能够处理重定向。将project-info.plist作为源代码打开,并确保您拥有有效的
    URL类型
    URL标识符
    URL方案
    。如代码块3所示
  • 步骤09。现在您的移动应用已准备好从服务器重定向
  • 步骤10。打开
    yourLocalServer/iOS/yos-social-php-master/sample/sampleapp.php
    文件。()
  • 步骤11。注释代码从97到106
  • 步骤12。按照代码块4中的指示放置代码
  • 第13步。运行您的项目,单击iOS应用程序中的按钮
  • 步骤14。应用程序将导航到您的网站页面。站点页面将进行身份验证并获取配置文件详细信息
  • 第15步。身份验证完成后,网站页面将重定向回您的移动应用程序,并提供详细信息,如性别、全名、出生日期、guid、个人资料图片url等
摘要

移动应用程序导航到服务器->服务器通过OAuth php管理身份验证。一旦认证服务器检索到配置文件详细信息,服务器将指示safari导航回您的移动应用程序。您的移动应用程序在代码块中获取所有详细信息

代码块1

 - (void)viewDidLoad {
    [super viewDidLoad];
    self.session = [YOSSession sessionWithConsumerKey:@"ConsumerKeyHere"
                                           andConsumerSecret:@"ConsumerSecretKeyHere"
                                            andApplicationId:@"AppKey"];
    BOOL hasSession = [self.session resumeSession];
    if(hasSession == FALSE) {
        // custom call back URL which will redirect to our-app.
        // 10.0.0.76/iOS/callback.php redirects 
        // to com.mymobileapps.currentApp.yahoo
        [self.session 
           sendUserToAuthorizationWithCallbackUrl:
           @"http://10.0.0.76/iOS/callback.php"];
    } else {
        [self sendRequests];
    }
}
- (IBAction)connectYahoo:(id)sender {
      [[UIApplication sharedApplication] 
           openURL:[NSURL URLWithString:
           @"http://yourLocalServer/iOS/yos-social-php-master/sample/sampleapp.php"
      ]];
}
代码块2

- (void)sendRequests {
    // initialize a user request for the logged-in user
    YOSUserRequest *request = [YOSUserRequest requestWithSession:self.session];

    // fetch the user's profile data
    [request fetchProfileWithDelegate:self];
}

- (void)requestDidFinishLoading:(YOSResponseData *)data {
    // parse the response text string into a dictionary
    NSDictionary *rspData = [NSJSONSerialization JSONObjectWithData:[data.responseText dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments error:nil];
    NSDictionary *profileData = [rspData objectForKey:@"profile"];

    // format a string using the nickname object from the profile.
    NSString *welcomeText = [NSString stringWithFormat:@"Hey %@ %@!",
                             [profileData objectForKey:@"givenName"],
                             [profileData objectForKey:@"familyName"]];
    NSLog(@"welcometext is %@",welcomeText);
    self.lblProfile.text = welcomeText;
}
- (BOOL)application:(UIApplication *)application
        openURL:(NSURL *)url
   sourceApplication:(NSString *)sourceApplication
     annotation:(id)annotation {

    if([[url scheme] isEqualToString:@"com.yourcompany.app.fsq"]) {
        return [self.obj_LoginHomeVCtr.foursquare handleOpenURL:url];
    } else if([[url scheme] isEqualToString:@"com.yourcompany.app.googleplus"]){
        return [GPPURLHandler handleURL:url
                  sourceApplication:sourceApplication
                         annotation:annotation];

    }else if([[url scheme] isEqualToString:@"fb188315544652080"]){
        return [FBAppCall handleOpenURL:url
                  sourceApplication:sourceApplication
                    fallbackHandler:^(FBAppCall *call) {
                        NSLog(@"In fallback handler");
                    }];
    } else if ([[url scheme] isEqualToString:@"com.yourcompany.app.yahoo"]){
        STLog(@"URL is %@",url);
        return YES;
    }
    return YES;
}
代码块3

- (BOOL)application: (UIApplication *)application
            openURL: (NSURL *)url
  sourceApplication: (NSString *)sourceApplication
         annotation: (id)annotation {
    NSString *str = [[url description] stringByReplacingOccurrencesOfString:@"com.mymobileapps.currentApp.yahoo://oauth-response?oauth_token=" withString:@""];
    NSArray *ar = [str componentsSeparatedByString:@"&oauth_verifier="];
    NSLog(@"oauth_token is %@",[ar objectAtIndex:0]);
    NSLog(@"oauth_verifier is %@",[ar objectAtIndex:1]);
    // How my session will get updated now with valid authentication done?
    return YES;
}
<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLName</key>
        <string>com.yourcompany.app.yahoo</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>com.yourcompany.app.yahoo</string>
        </array>
    </dict>
</array>
CbundleUrlTypes
CbundleTypeRole
编辑
循环流化床锅炉