instagram_graph_api 0.0.8 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 64d1de43c28966fc8f80eb2b9724c17eb15e0ad3a7ecde0df75419fbaf90296d
4
- data.tar.gz: f64f55b10813fe6f5921d33b3a3a1e8e5c331a04c6898abbb9d51f620af25e0b
3
+ metadata.gz: 8488ee797ab4f487ebf19776f064806f7347631fc38354cf6722112730c8c737
4
+ data.tar.gz: df891d813d3d93d55e8be002d5ac6cba0fafd7d83cedfc4164dda5402053daf4
5
5
  SHA512:
6
- metadata.gz: ca56aee8b68c7290a25a5bc9ded5cecde8ff21347693872cf58b9d0abe759a5dd02cc2cd5f6f42383cfb429502b6fe3099fce87deecb6688eaae88eed5a81625
7
- data.tar.gz: 24e610740383774f98a80ce1dd04896a34262d6c81b7facbeb7ecbf7da0882f9f427893b075235eda4fc848e2701fffc9a94b3dcfaeea4bcca79c6ec4525f002
6
+ metadata.gz: 0b3d554de5a6a3e930a55b8dbb00a426acb2212ef8dfd8dd03425343d7e2bdb1b127441f8058fbb1c78d1bd51d7de31a0fd2cad56680d4a9197a05b8793dc519
7
+ data.tar.gz: d281bc46eb5d3e8e790f118653e11c00c70cb0071e9405225c0f20bfa49062b39f8b042b013682d14435b2fd55ba9e57dc28eb3c9cd9ba76923f573e17c6d8ff
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 IG business account info
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 i.e before/after/limit etc
52
68
  ```
53
69
 
54
70
  ## Development
@@ -33,7 +33,7 @@ Gem::Specification.new do |spec|
33
33
  spec.require_paths = ["lib"]
34
34
 
35
35
  spec.add_development_dependency "bundler", "~> 1.16"
36
- spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "rake", ">= 12.3.3"
37
37
  spec.add_development_dependency "pry"
38
38
  spec.add_dependency "koala"
39
39
  end
@@ -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
@@ -14,7 +14,7 @@ module InstagramGraphApi
14
14
  def discover_user_media(username, fields = nil, options={})
15
15
  fields ||= "caption,media_url,media_type,like_count,comments_count,id"
16
16
  page_options = ".after(#{options['after']})" if options["after"]
17
- page_options = ".before(#{options['before']})" if options["before"]
17
+ page_options = ".after(#{options['before']})" if options["before"]
18
18
  discover_user(username, "media#{page_options}{#{fields}}")
19
19
  end
20
20
  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
- query = "#{entity}?fields=#{MEDIA_INFO_HASH[type.to_sym]}"
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}")
@@ -1,3 +1,3 @@
1
1
  module InstagramGraphApi
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.13"
3
3
  end
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.8
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rakesh
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-09-28 00:00:00.000000000 Z
11
+ date: 2020-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: 12.3.3
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: 12.3.3
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: pry
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -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
- rubyforge_project:
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