Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.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
按ID查找Instagram媒体url_Instagram_Instagram Api - Fatal编程技术网

按ID查找Instagram媒体url

按ID查找Instagram媒体url,instagram,instagram-api,Instagram,Instagram Api,多亏了一个不太正式的HTTP呼叫,我找到了Instagram帖子的媒体ID、图像URL和用户名 但是我需要Instagram上每个帖子的URL,我不知道如何找到它 是否有像instagram.com/something/{mediaID}这样的URL重定向到instagram.com/p/{mediaSlug},或者其他通过媒体ID查找slug的方法(当然不使用官方API!) 例如,我有: 唯一号码:1238578393243739028_1408429375 媒体ID:123857839324

多亏了一个不太正式的HTTP呼叫,我找到了Instagram帖子的媒体ID、图像URL和用户名

但是我需要Instagram上每个帖子的URL,我不知道如何找到它

是否有像
instagram.com/something/{mediaID}
这样的URL重定向到
instagram.com/p/{mediaSlug}
,或者其他通过媒体ID查找slug的方法(当然不使用官方API!)

例如,我有:

唯一号码:1238578393243739028_1408429375

媒体ID:1238578393243739028

用户ID:1408429375

我会:

谢谢你的帮助

这可能会有帮助:

1) 自己生成URL的算法

2) 此外,Instagram具有专用API端点,可通过媒体id生成URL: 但它是受cookie sessionid保护的,基于这篇伟大的文章,下面是关于将数字ID转换为字符串ID的ruby实现示例:

def translate(post_id)
  dict = [?A..?Z, ?a..?z, 0..9].map(&:to_a).flatten
  dict += ['-', '_']

  post_id = post_id.split('_').first.to_i
  to_radix(post_id, 64).map { |d| dict[d] }.join
end

def to_radix(int, radix)
  int == 0 ? [] : (to_radix(int / radix, radix) + [int % radix])
end

在这里,您只需致电
translate('1238578393243739028_1408429375')
,然后返回
BEwUHyDxGOU

我找到了iOS objective-C的解决方案:

-(NSString *) getInstagramPostId:(NSString *)mediaId {
NSString *postId = @"";
@try {
    NSArray *myArray = [mediaId componentsSeparatedByString:@"_"];
    NSString *longValue = [NSString stringWithFormat:@"%@",myArray[0]];
    long itemId = [longValue longLongValue];
    NSString *alphabet = @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
    while (itemId > 0) {
        long remainder = (itemId % 64);
        itemId = (itemId - remainder) / 64;
        unsigned char charToUse = [alphabet characterAtIndex:(int)remainder];
        postId = [NSString stringWithFormat:@"%c%@",charToUse , postId];
    }
} @catch(NSException *exception) {
    NSLog(@"%@",exception);
}
return postId;}
Java解决方案:

func getInstagramPostId(_ mediaId: String?) -> String? {
    var postId = ""
    do {
        let myArray = mediaId?.components(separatedBy: "_")
        let longValue = "\(String(describing: myArray?[0]))"
        var itemId = Int(Int64(longValue) ?? 0)
        let alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
        while itemId > 0 {
            let remainder: Int = itemId % 64
            itemId = (itemId - remainder) / 64

            let charToUse = alphabet[alphabet.index(alphabet.startIndex, offsetBy: Int(remainder))]
            postId = "\(charToUse)\(postId)"
        }
    }
    return postId
}
public static string getInstagramPostId(string mediaId)
       {
           string postId = "";
           try
           {
               long id = long.Parse(mediaId.Substring(0, mediaId.IndexOf('_')));
               string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
               while (id > 0)
               {
                   long remainder = (id % 64);
                   id = (id - remainder) / 64;

                   int a = (int)remainder + int.Parse(postId);

                   postId = "" + alphabet[a];
               }
           }
           catch (Exception e)
           {
               Console.Write(e.StackTrace);

           }

           return postId;
       }
公共静态字符串getInstagramPostId(字符串mediaId){
字符串posted=“”;
试一试{
long id=long.parseLong(mediaId.substring(0,mediaId.indexOf(“”));
字符串字母表=“ABCDEFGHIJKLMNOPQRSTUVXYZABCDFGHIJKLMNOPQRSTUVXYZ0123456789-”;
而(id>0){
长余数=(id%64);
id=(id-余数)/64;
postId=字母表字符((int)余数)+postId;
}
}捕获(例外e){
e、 printStackTrace();
}
回帖;
}

使用大整数包()

Swift 4.2解决方案:

func getInstagramPostId(_ mediaId: String?) -> String? {
    var postId = ""
    do {
        let myArray = mediaId?.components(separatedBy: "_")
        let longValue = "\(String(describing: myArray?[0]))"
        var itemId = Int(Int64(longValue) ?? 0)
        let alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
        while itemId > 0 {
            let remainder: Int = itemId % 64
            itemId = (itemId - remainder) / 64

            let charToUse = alphabet[alphabet.index(alphabet.startIndex, offsetBy: Int(remainder))]
            postId = "\(charToUse)\(postId)"
        }
    }
    return postId
}
public static string getInstagramPostId(string mediaId)
       {
           string postId = "";
           try
           {
               long id = long.Parse(mediaId.Substring(0, mediaId.IndexOf('_')));
               string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
               while (id > 0)
               {
                   long remainder = (id % 64);
                   id = (id - remainder) / 64;

                   int a = (int)remainder + int.Parse(postId);

                   postId = "" + alphabet[a];
               }
           }
           catch (Exception e)
           {
               Console.Write(e.StackTrace);

           }

           return postId;
       }
C#解决方案:

func getInstagramPostId(_ mediaId: String?) -> String? {
    var postId = ""
    do {
        let myArray = mediaId?.components(separatedBy: "_")
        let longValue = "\(String(describing: myArray?[0]))"
        var itemId = Int(Int64(longValue) ?? 0)
        let alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
        while itemId > 0 {
            let remainder: Int = itemId % 64
            itemId = (itemId - remainder) / 64

            let charToUse = alphabet[alphabet.index(alphabet.startIndex, offsetBy: Int(remainder))]
            postId = "\(charToUse)\(postId)"
        }
    }
    return postId
}
public static string getInstagramPostId(string mediaId)
       {
           string postId = "";
           try
           {
               long id = long.Parse(mediaId.Substring(0, mediaId.IndexOf('_')));
               string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
               while (id > 0)
               {
                   long remainder = (id % 64);
                   id = (id - remainder) / 64;

                   int a = (int)remainder + int.Parse(postId);

                   postId = "" + alphabet[a];
               }
           }
           catch (Exception e)
           {
               Console.Write(e.StackTrace);

           }

           return postId;
       }
C#溶液(测试)

公共静态字符串getInstagramPostId(字符串mediaId)
{
字符串posted=“”;
尝试
{
long id=long.Parse(mediaId.Substring(0,mediaId.IndexOf(“”));
字符串字母表=“ABCDEFGHIJKLMNOPQRSTUVXYZABCDFGHIJKLMNOPQRSTUVXYZ0123456789-”;
而(id>0)
{
长余数=(id%64);
id=(id-余数)/64;
postId=字母表元素((int)余数)+postId;
}
}
捕获(例外e)
{
Console.Write(如StackTrace);
}
回帖;

}
虽然这可能会提供问题的答案,但不鼓励只提供答案的链接。