Pie*_*rre 9 instagram instagram-api
由于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的算法 http://carrot.is/coding/instagram-ids
2)此外,Instagram具有专用API终结点,可通过media_id生成URL:https ://i.instagram.com/api/v1/media/1212073297261212121_121212123111/permalink/, 但受cookie sessionid保护
Java解决方案:
public static String getInstagramPostId(String mediaId) {
String postId = "";
try {
long id = Long.parseLong(mediaId.substring(0, mediaId.indexOf('_')));
String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
while (id > 0) {
long remainder = (id % 64);
id = (id - remainder) / 64;
postId = alphabet.charAt((int)remainder) + postId;
}
} catch (Exception e) {
e.printStackTrace();
}
return postId;
}
Run Code Online (Sandbox Code Playgroud)
使用 big-integer 包分享 JavaScript 中的实现(https://www.npmjs.com/package/big-integer)
var bigInt = require('big-integer');
function getShortcodeFromTag(tag) {
let id = bigInt(tag.split('_', 1)[0]);
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
let remainder;
let shortcode = '';
while (id.greater(0)) {
let division = id.divmod(64);
id = division.quotient;
shortcode = `${alphabet.charAt(division.remainder)}${shortcode}`;
}
return shortcode;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
27235 次 |
| 最近记录: |