我試圖獲取 facebook 移動帖子。
$VAR1 = {
"mf_story_key" => "225164133113094",
"page_id" => "102820022014173",
"page_insights" => {
"102820022014173" => {
"actor_id" => "102820022014173",
"page_id" => "102820022014173",
"page_id_type" => "page",
"post_context" => {
"publish_time" => "1641702174",
"story_name" => "EntStatusCreationStory"
},
"psn" => "EntStatusCreationStory",
"role" => 1,
}
},
"story_attachment_style" => "album",
};
$publish_time = $VAR1->{page_insights}{102820022014173}{post_context}{publish_time};
如果 102820022014173 是動態值,我如何訪問沒有具體的 publish_time 值?
uj5u.com熱心網友回復:
您需要獲取keyspage_insights 哈希,然后遍歷它們。
use strict;
use warnings;
use 5.010;
my $post = {
"mf_story_key" => "225164133113094",
"page_id" => "102820022014173",
"page_insights" => {
"102820022014173" => {
"actor_id" => "102820022014173",
"page_id" => "102820022014173",
"page_id_type" => "page",
"post_context" => {
"publish_time" => "1641702174",
"story_name" => "EntStatusCreationStory"
},
"psn" => "EntStatusCreationStory",
"role" => 1,
}
},
"story_attachment_style" => "album",
};
my $insights = $post->{page_insights};
my @insight_ids = keys %{$insights};
for my $id ( @insight_ids ) {
say "ID $id was published at ",
$insights->{$id}{post_context}{publish_time};
}
給
ID 102820022014173 was published at 1641702174
uj5u.com熱心網友回復:
for my $page_insight ( values( %{ $VAR1->{page_insights} } ) ) {
my $publish_time = $page_insight->{post_context}{publish_time};
...
}
如果總是只有一個元素,
my $page_insight = ( values( %{ $VAR1->{page_insights} } )[0];
my $publish_time = $page_insight->{post_context}{publish_time};
...
(如果您愿意,可以將這兩個陳述句結合起來。)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/409718.html
標籤:
