instagram_graph_api 0.0.7 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -1
- data/lib/instagram_graph_api/client.rb +2 -4
- data/lib/instagram_graph_api/client/insights.rb +21 -0
- data/lib/instagram_graph_api/client/media.rb +4 -17
- data/lib/instagram_graph_api/client/tag.rb +21 -0
- data/lib/instagram_graph_api/client/users.rb +8 -0
- data/lib/instagram_graph_api/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15be12b49a31da27c8d3978f2aaebb969091477d1c4d5e1a842dc4b9fd3f7b54
|
4
|
+
data.tar.gz: 5a20b15b6abf7dbc84cbccecfaecb7fd9ca46978140e6b548104c6e314d5debf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 743679160256cd91df0a4466adea7c5c9bb68c12991c87f855986f758ca9f4de41522fc590b1098beb39fbcfb0419449ca7341963d2996cd98d49380aa180de7
|
7
|
+
data.tar.gz: 03daa42f1f38d45dd5d870f658c83ca44cca73dae56a580652a9143f790ef057f6d590b469c33997ca9ff64253317f86c48bf5c18667a4fc9ddaea27fdd818cc
|
data/README.md
CHANGED
@@ -25,8 +25,14 @@ client = InstagramGraphApi.client(ACCESS_TOKEN)
|
|
25
25
|
|
26
26
|
#get an arraay of business accounts linked to the access_token
|
27
27
|
client.ig_business_accounts
|
28
|
+
#get an array of connected IG accounts linked to the access_token
|
29
|
+
client.connected_ig_accounts
|
28
30
|
|
29
|
-
#get
|
31
|
+
#to get specific fields from "id,name,biography,ig_id,followers_count,profile_picture_url,username"
|
32
|
+
client.ig_business_accounts("name,followers_count")
|
33
|
+
client.connected_ig_accounts("name,followers_count")
|
34
|
+
|
35
|
+
#get IG business account/ Connected IG account info
|
30
36
|
client.get_account_info(IG_BUSINESS_ID)
|
31
37
|
#to get specific fields
|
32
38
|
fields = "name, biography"
|
@@ -49,6 +55,16 @@ client.discover_user(USERNAME, fields)
|
|
49
55
|
|
50
56
|
#discover user media, fields can be "caption,media_url,media_type,like_count,comments_count,id"
|
51
57
|
client.discover_user_media(USERNAME, fields)
|
58
|
+
|
59
|
+
#Search for a tag,
|
60
|
+
client.tag_media(page_token, tag_name)
|
61
|
+
#fields can be "media_type,comments_count,like_count,media_url,permalink"
|
62
|
+
fields="media_url,permalink"
|
63
|
+
client.tag_media(page_token, tag_name, fields)
|
64
|
+
#custom edge can be provided, default is 'top_media'
|
65
|
+
tag_media = client.tag_media(page_token, tag_name, edge: "recent_media")
|
66
|
+
# Note: We can run `tag_media.next_page` to fetch next set of results
|
67
|
+
# additional arguent options can also be passed for page params like before/after or any other custom filter
|
52
68
|
```
|
53
69
|
|
54
70
|
## Development
|
@@ -4,12 +4,10 @@ module InstagramGraphApi
|
|
4
4
|
class Client < Koala::Facebook::API
|
5
5
|
Dir[File.expand_path('../client/*.rb', __FILE__)].each{|f| require f}
|
6
6
|
|
7
|
+
include InstagramGraphApi::Client::Insights
|
7
8
|
include InstagramGraphApi::Client::Users
|
8
9
|
include InstagramGraphApi::Client::Media
|
9
10
|
include InstagramGraphApi::Client::Discovery
|
10
|
-
|
11
|
-
def initialize(media_id = nil, access_token)
|
12
|
-
super(access_token)
|
13
|
-
end
|
11
|
+
include InstagramGraphApi::Client::Tag
|
14
12
|
end
|
15
13
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module InstagramGraphApi
|
2
|
+
class Client
|
3
|
+
module Insights
|
4
|
+
|
5
|
+
METRIC_HASH = {
|
6
|
+
image: 'impressions,reach',
|
7
|
+
video: 'impressions,reach,video_views',
|
8
|
+
story: 'impressions,replies,reach,taps_forward,taps_back,exits'
|
9
|
+
}
|
10
|
+
|
11
|
+
def insights(object_id, type: "image", metrics: nil)
|
12
|
+
metrics ||= METRIC_HASH[type.to_sym]
|
13
|
+
@raw_insights = get_connections(object_id, "insights?metric=#{metrics}")
|
14
|
+
@raw_insights.reduce({}) do |result, insight_data|
|
15
|
+
result[insight_data["name"]] = insight_data["values"].first["value"]
|
16
|
+
result
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -3,12 +3,6 @@ module InstagramGraphApi
|
|
3
3
|
module Media
|
4
4
|
attr_accessor :media_info, :raw_insights
|
5
5
|
|
6
|
-
METRIC_HASH = {
|
7
|
-
image: 'impressions,reach',
|
8
|
-
video: 'impressions,reach,video_views',
|
9
|
-
story: 'impressions,replies,reach,taps_forward,taps_back,exits'
|
10
|
-
}
|
11
|
-
|
12
6
|
MEDIA_INFO_HASH = {
|
13
7
|
image: "comments_count,like_count,media_type,"\
|
14
8
|
"media_url,permalink,timestamp,thumbnail_url",
|
@@ -18,27 +12,20 @@ module InstagramGraphApi
|
|
18
12
|
"timestamp,thumbnail_url"
|
19
13
|
}
|
20
14
|
|
21
|
-
def get_user_recent_media(id, type: "image", options: {})
|
15
|
+
def get_user_recent_media(id, fields = nil, type: "image", options: {})
|
22
16
|
entity = type.eql?("story") ? "stories" : "media"
|
23
|
-
|
17
|
+
fields ||= MEDIA_INFO_HASH[type.to_sym]
|
18
|
+
query = "#{entity}?fields=#{fields}"
|
24
19
|
query += "&after=#{options[:after]}" if options[:after]
|
25
20
|
query += "&before=#{options[:before]}" if options[:before]
|
26
21
|
get_connections(id, query)
|
27
22
|
end
|
28
23
|
|
29
|
-
def get_media_details(media_id, type: "image")
|
24
|
+
def get_media_details(media_id, fields = nil, type: "image")
|
30
25
|
fields ||= MEDIA_INFO_HASH[type.to_sym]
|
31
26
|
get_connections(media_id , "?fields=#{fields}")
|
32
27
|
end
|
33
28
|
|
34
|
-
def insights(media_id, type: "image", metrics: nil)
|
35
|
-
metrics ||= METRIC_HASH[type.to_sym]
|
36
|
-
@raw_insights = get_connections(media_id , "insights?metric=#{metrics}")
|
37
|
-
@raw_insights.reduce({}) do |result, insight_data|
|
38
|
-
result[insight_data["name"]] = insight_data["values"].first["value"]
|
39
|
-
result
|
40
|
-
end
|
41
|
-
end
|
42
29
|
end
|
43
30
|
end
|
44
31
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module InstagramGraphApi
|
2
|
+
class Client
|
3
|
+
module Tag
|
4
|
+
def tag_media(page_token, tag_name, fields = nil, edge: "top_media", options: {})
|
5
|
+
user_id = get_ig_id_from_token(page_token)
|
6
|
+
tag_info = graph_call("ig_hashtag_search?user_id=#{user_id}&q=#{tag_name}")[0]
|
7
|
+
fields ||= "id,media_type,comments_count,like_count,media_url,permalink"
|
8
|
+
query = "#{edge}?user_id=#{user_id}&fields=#{fields}"
|
9
|
+
query += options.reduce(""){|s, (k, v)| s+= "&#{k}=#{v}" }
|
10
|
+
get_connections(tag_info["id"], query)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def get_ig_id_from_token(token)
|
16
|
+
account_info = get_connections('me', "?fields=connected_instagram_account")
|
17
|
+
account_info.dig("connected_instagram_account", "id")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -9,6 +9,14 @@ module InstagramGraphApi
|
|
9
9
|
end.compact
|
10
10
|
end
|
11
11
|
|
12
|
+
def connected_ig_accounts(fields = nil)
|
13
|
+
fields ||= 'id,name,biography,ig_id,followers_count,profile_picture_url,username'
|
14
|
+
accounts = get_pages("?fields=connected_instagram_account{#{fields}}")
|
15
|
+
accounts.map do |a|
|
16
|
+
a["connected_instagram_account"].merge(page_id: a["id"]) if a["connected_instagram_account"]
|
17
|
+
end.compact
|
18
|
+
end
|
19
|
+
|
12
20
|
def get_account_info(ig_account_id, fields = nil)
|
13
21
|
fields ||= "biography,followers_count,ig_id,name,profile_picture_url,username,id"
|
14
22
|
get_connections(ig_account_id , "?fields=#{fields}")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: instagram_graph_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rakesh
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -86,7 +86,9 @@ files:
|
|
86
86
|
- lib/instagram_graph_api.rb
|
87
87
|
- lib/instagram_graph_api/client.rb
|
88
88
|
- lib/instagram_graph_api/client/discovery.rb
|
89
|
+
- lib/instagram_graph_api/client/insights.rb
|
89
90
|
- lib/instagram_graph_api/client/media.rb
|
91
|
+
- lib/instagram_graph_api/client/tag.rb
|
90
92
|
- lib/instagram_graph_api/client/users.rb
|
91
93
|
- lib/instagram_graph_api/version.rb
|
92
94
|
homepage: https://github.com/rakeshpatra/instagram_graph_api
|
@@ -108,8 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
110
|
- !ruby/object:Gem::Version
|
109
111
|
version: '0'
|
110
112
|
requirements: []
|
111
|
-
|
112
|
-
rubygems_version: 2.7.7
|
113
|
+
rubygems_version: 3.0.6
|
113
114
|
signing_key:
|
114
115
|
specification_version: 4
|
115
116
|
summary: Instagram Graph API
|