Skip to content

Commit

Permalink
Merge pull request #9 from GtheSheep/master
Browse files Browse the repository at this point in the history
Fix - Remove video_title from media stream and fix media_insights for reels
  • Loading branch information
prratek authored Aug 19, 2022
2 parents 504d189 + 5e653ae commit 7237e9b
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions tap_instagram/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ class MediaStream(InstagramStream):
"thumbnail_url",
"timestamp",
"username",
"video_title",
]
# Optionally, you may also use `schema_filepath` in place of `schema`:
# schema_filepath = SCHEMAS_DIR / "users.json"
Expand Down Expand Up @@ -178,12 +177,6 @@ class MediaStream(InstagramStream):
th.StringType,
description="Username of user who created the media.",
),
th.Property(
"video_title",
th.StringType,
description="Instagram TV media title. Will not be returned if targeting an Instagram TV video created on "
"or after October 5, 2021.",
),
).to_dict()

def make_since_param(self, context: Optional[dict]) -> datetime:
Expand Down Expand Up @@ -244,7 +237,6 @@ class StoriesStream(InstagramStream):
"thumbnail_url",
"timestamp",
"username",
"video_title",
]
# Optionally, you may also use `schema_filepath` in place of `schema`:
# schema_filepath = SCHEMAS_DIR / "users.json"
Expand Down Expand Up @@ -341,12 +333,6 @@ class StoriesStream(InstagramStream):
th.StringType,
description="Username of user who created the media.",
),
th.Property(
"video_title",
th.StringType,
description="Instagram TV media title. Will not be returned if targeting an Instagram TV video created on "
"or after October 5, 2021.",
),
).to_dict()

def get_url_params(
Expand Down Expand Up @@ -381,7 +367,7 @@ class MediaChildrenStream(MediaStream):
parent_stream_type = MediaStream
state_partitioning_keys = ["user_id"]
path = "/{media_id}/children" # media_id is populated using child context keys from MediaStream
# caption, comments_count, is_comment_enabled, like_count, media_product_type, video_title
# caption, comments_count, is_comment_enabled, like_count, media_product_type
# not available on album children
# TODO: Is media_product_type available on children of some media types? carousel vs album children?
# https://developers.facebook.com/docs/instagram-api/reference/ig-media#fields
Expand Down Expand Up @@ -414,7 +400,7 @@ class MediaInsightsStream(InstagramStream):
path = "/{media_id}/insights"
parent_stream_type = MediaStream
state_partitioning_keys = ["user_id"]
primary_keys = "id"
primary_keys = ["id"]
replication_key = None
records_jsonpath = "$.data[*]"

Expand Down Expand Up @@ -474,6 +460,16 @@ def _metrics_for_media_type(media_type: str, media_product_type: str):
"taps_forward",
"taps_back",
]
elif media_product_type == "REELS":
return [
"comments",
"likes",
"plays",
"reach",
"saved",
"shares",
"total_interactions",
]
else: # media_product_type is "AD" or "FEED"
metrics = [
"engagement",
Expand Down Expand Up @@ -578,7 +574,7 @@ class StoryInsightsStream(InstagramStream):
path = "/{media_id}/insights"
parent_stream_type = StoriesStream
state_partitioning_keys = ["user_id"]
primary_keys = "id"
primary_keys = ["id"]
replication_key = None
records_jsonpath = "$.data[*]"

Expand Down Expand Up @@ -722,7 +718,7 @@ def parse_response(self, response: requests.Response) -> Iterable[dict]:
class UserInsightsStream(InstagramStream):
parent_stream_type = UsersStream
path = "/{user_id}/insights" # user_id is populated using child context keys from UsersStream
primary_keys = "id"
primary_keys = ["id"]
replication_key = "end_time"
records_jsonpath = "$.data[*]"
has_pagination = True
Expand Down

0 comments on commit 7237e9b

Please sign in to comment.