ios - 从任何 URL 获取特定图像,就像 Facebook 那样

标签 ios objective-c xcode nsurl

我的问题可能看起来与其他问题相似,但实际上并非如此。(据我所知)。我无法理解如何像 Facebook 那样从任何 URL 获取特定图像,我无法向您展示屏幕截图,因为我没有真实设备。但我可以向您展示从 MAC 截取的 Skype 屏幕截图。任何帮助将不胜感激。谢谢。 enter image description here
编辑:
我使用这个 link 得到了图标但它很小,我想要更大的尺寸。

最佳答案

终于,我得到了答案。这可能对您有帮助,这就是我发布此答案的原因。使用此宏
#define FACEBOOK_GRAPH @"https://graph.facebook.com/v2 .3/oauth/access_token?client_id=USE_YOUR_CLIENT_ID&client_secret=USE_YOUR_CLIENT_SECRET&grant_type=client_credentials"
注意:您可以通过在 developer.facebook 上注册您的应用程序来获取“client_id”和“client_secret” .com
现在调用 FACEBOOK_GRAPH 如下所示。

AFHTTPRequestOperationManager* manager = [AFHTTPRequestOperationManager manager];
    //manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    manager.responseSerializer=[AFJSONResponseSerializer new];
    AFHTTPRequestOperation* operation = [manager POST:FACEBOOK_GRAPH parameters:nil
                                              success:^(AFHTTPRequestOperation* op, id responseObject){
                                                  //here pass your URL as a string and access Token as a string, access token will found in responseObject
                                              }
                                              failure:^(AFHTTPRequestOperation* op, NSError* error){
                                                  NSLog(@"\n\nerror--->%@\n\n",error.localizedDescription);
                                              }];
    [operation start];

现在是第二种从我们的 URL 获取图像的方法,使用我们的 URL 和访问从上述方法获取的 Token

url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    token = [token stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    AFHTTPRequestOperationManager* manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer=[AFJSONResponseSerializer new];
    AFHTTPRequestOperation* operation = [manager POST:[NSString stringWithFormat:@"https://graph.facebook.com/v2.3/?id=%@&access_token=%@&scrape=true",url,token] parameters:nil success:^(AFHTTPRequestOperation* op, id responseObject){
        NSLog(@"\n\nData Response==\n%@\n",responseObject);
        //you will get Image URL in response
    }failure:^(AFHTTPRequestOperation* op, NSError* error){
                                                NSLog(@"##error--->\n%@",error.localizedDescription);
                                         }];
    [operation start];

关于ios - 从任何 URL 获取特定图像,就像 Facebook 那样,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31851482/

相关文章:

ios - 在 iOS 应用程序中支持 Apple Music 和 Spotify 的最佳方式是什么?

swift - 如何在 Swift 中的 UILabel 上设置 CAShapeLayer 掩码

iphone - 在 Resources 文件夹下添加 iOS 图标和启动图像

ios - 如何从我的 iOS 应用打开 Instagram 应用?

ios - 当 SceneKit 动画停止时,SpriteKit 的动画覆盖在 SceneKit 上停止

c# - xamarin ios c# 下划线 UIButton 文本

iphone - 两部 iPhone 之间的距离

ios - refreshcontrol 结束刷新必须等待子类

objective-c - NSTextView:以编程方式格式化文本

iphone - 在文件中存储 NSArray/NSMuatbleArray