見ていただいてありがとうございます。
Google+の自分の投稿を他のサイトに表示したいと考えています。
そこで自分の投稿の詳細を取得してeachで回して最新の9件を表示しようとしているのですが、以下のエラーが出て表示されません。
undefined method `items' for ["kind", "plus#activityFeed"]:Array
Controller
class HogeController < ApplicationController require 'google/api_client' require 'json' def index client = Google::APIClient.new( application_name: 'Example Ruby application', application_version: '1.0.0' ) client.key = "**************************" client.authorization = nil result = client.execute( api_method: client.discovered_api(:plus).activities.list, parameters: { collection: "public", userId: ***************** } ) @users = result.data.to_json end end
index.html.erbのソース
<center> <div style="width:930px;"> <% @users.first(9).each do |user| %> <div style="float:left;width: 300px;height: 400px;margin:3px; border: 2px solid blue; "> <% link = user.items.url %> <% name = user.items.actor.displayName %> <% coment = user.items.title %> <% img = user.items.object.attachments %> <%= link_to name, @admin.instagrams_url, :target=>["_blank"] %><br> <%= coment %><br> <%= link_to image_tag(img, :class => "img- rounded" ), @admin.instagrams_url, :target=>["_blank"] %> </div> <% end %> <br clear="both"/> </div> </center>
試しにindex.html.erbを「<%= @users %>」だけにしたところ以下のJSONを取得できていました。
{ "kind": "plus#activityFeed", "etag": "\"4OZ_Kt6ujOh1jaML_U6RM6APqoE/_0SmOsuNO4HJllkV83exN-HCnKc\"", "title": "Google+ List of Activities for Collection PUBLIC", "updated": "2016-04-26T04:34:20.759Z", "items": [ { "kind": "plus#activity", "etag": "\"4OZ_Kt6ujOh1jaML_U6RM6APqoE/GE9BFTCcw-pt7iSspiBt9oy23lc\"", "title": "信じられないだろ・・・\nこれでグミなんだぜ・・・\n\n#グミ\n#クマ", "published": "2016-04-26T04:34:20.759Z", "updated": "2016-04-26T04:34:20.759Z", "id": "z13my3toswewyzxks220eporttighvqd0", "url": "https://plus.google.com/114624284244149933026/posts/5Aqgjf5owKA", "actor": { "id": "114624284244149933026", "displayName": "田中琢磨", "url": "https://plus.google.com/114624284244149933026", "image": { "url": "https://lh5.googleusercontent.com/-Vy7vaAD81i0/AAAAAAAAAAI/AAAAAAAAABE/mnXdlb-q2VM/photo.jpg?sz=50" }, "verification": { "adHocVerified": "UNKNOWN_VERIFICATION_STATUS" } }, "verb": "post", "object": { "objectType": "note", "actor": { "verification": { "adHocVerified": "UNKNOWN_VERIFICATION_STATUS" } }, "content": "信じられないだろ・・・\u003cbr /\u003eこれでグミなんだぜ・・・\u003cbr /\u003e\u003cbr /\u003e\u003ca rel=\"nofollow\" class=\"ot-hashtag\" href=\"https://plus.google.com/s/%23%E3%82%B0%E3%83%9F\"\u003e#グミ\u003c/a\u003e\u003cbr /\u003e\u003ca rel=\"nofollow\" class=\"ot-hashtag\" href=\"https://plus.google.com/s/%23%E3%82%AF%E3%83%9E\"\u003e#クマ\u003c/a\u003e\ufeff", "url": "https://plus.google.com/114624284244149933026/posts/5Aqgjf5owKA", "replies": { "totalItems": 0, "selfLink": "https://www.googleapis.com/plus/v1/activities/z13my3toswewyzxks220eporttighvqd0/comments" }, "plusoners": { "totalItems": 0, "selfLink": "https://www.googleapis.com/plus/v1/activities/z13my3toswewyzxks220eporttighvqd0/people/plusoners" }, "resharers": { "totalItems": 0, "selfLink": "https://www.googleapis.com/plus/v1/activities/z13my3toswewyzxks220eporttighvqd0/people/resharers" }, "attachments": [ { "objectType": "photo", "displayName": "信じられないだろ・・・\nこれでグミなんだぜ・・・\n\n#グミ\n#クマ", "id": "114624284244149933026.6277718594201482882", "content": "kumagumi.jpg", "url": "https://plus.google.com/photos/114624284244149933026/albums/6277718590126254161/6277718594201482882", "image": { "url": "https://lh3.googleusercontent.com/-9bBbRZogmFI/Vx7vzPc-doI/AAAAAAAAAHc/fo-PF1nHTl8q18HOTMQBoU1TGctzA2b7A/w506-h750/kumagumi.jpg", "type": "image/jpeg" }, "fullImage": { "url": "https://lh3.googleusercontent.com/-9bBbRZogmFI/Vx7vzPc-doI/AAAAAAAAAHc/fo-PF1nHTl8q18HOTMQBoU1TGctzA2b7A/w960-h592/kumagumi.jpg", "type": "image/jpeg", "height": 592, "width": 960 } } ] }, "provider": { "title": "Google+" }, "access": { "kind": "plus#acl", "description": "Public", "items": [ { "type": "public" } ] } }, { "kind": "plus#activity", "etag": "\"4OZ_Kt6ujOh1jaML_U6RM6APqoE/ic0vNiJnuEuZ1k0x1ipIbaXYGS0\"", "title": "灯台だけど、ちょっとお城っぽいね\n#灯台\n#夕焼け", "published": "2016-04-26T04:32:59.132Z", "updated": "2016-04-26T04:32:59.132Z", "id": "z12xs1tanzijtheez220eporttighvqd0", "url": "https://plus.google.com/114624284244149933026/posts/Gwju3YpRCYS", "actor": {
初歩的なミスかと思うのですが、何が原因か分かりません。
どなたかご教示お願いします。
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/04/27 03:35
2016/04/27 04:31
2016/04/27 05:32