【问题标题】:Android Login with Google Plus Account使用 Google Plus 帐户登录 Android
【发布时间】:2023-12-27 12:56:01
【问题描述】:

我按照本教程使用 Google+ API 成功登录了我的 Google Plus 帐户:

Android Login with Google Plus Account

并获得了一些用户的信息(姓名、电子邮件、个人资料 URL、图片等)。

我面临的问题是我无法获取用户的活动(我的意思是用户“墙”上的最后帖子)。 我知道使用 Google Plus API 我只能获得公共活动,但我什至无法获得这些。 我使用的代码是

            // This sample assumes a client object has been created.
            // To learn more about creating a client, check out the starter:
            //  https://developers.google.com/+/quickstart/java
            Plus.Activities.List listActivities = plus.activities().list("me", "public");
            listActivities.setMaxResults(5L);

            // Execute the request for the first page
            ActivityFeed activityFeed = listActivities.execute();

            // Unwrap the request and extract the pieces we want
            List<Activity> activities = activityFeed.getItems();

            // Loop through until we arrive at an empty page
            while (activities != null) {
                for (Activity activity : activities) {
                    System.out.println("ID " + activity.getId() + " Content: " +
                            activity.getObject().getContent());
                }

                // We will know we are on the last page when the next page token is null.
                // If this is the case, break.
                if (activityFeed.getNextPageToken() == null) {
                    break;
                }

                // Prepare to request the next page of activities
                listActivities.setPageToken(activityFeed.getNextPageToken());

                // Execute and process the next page request
                activityFeed = listActivities.execute();
                activities = activityFeed.getItems();
            }

我是从 Google+ API 官方网站获得的,地址是:

Google+ Platform: Activities: list

当我尝试编译和运行时,我会收到以下错误消息:

Error:Execution failed for task ':app:compileDebugJava'.
> Compilation failed; see the compiler error output for details.
Error:(207, 21) error: cannot find symbol class Activities
Error:(207, 55) error: cannot find symbol variable plus
Error:(211, 17) error: cannot find symbol class ActivityFeed
Error:(214, 17) error: cannot find symbol class List
Error:(219, 60) error: cannot find symbol method getId()
Error:(220, 41) error: cannot find symbol method getObject()

有人可以帮助我吗? 非常感谢。

【问题讨论】:

标签: java android google-plus google-signin


【解决方案1】:

您使用的示例是使用来自https://github.com/googleplus/gplus-quickstart-java.git 的 (google-api-services-plus..jar) API,而您的应用程序使用的是 Android Google Messaging Services API。

我猜你的 Plus 导入是 com.google.android.gms.plus.Plus? (这是你想在 Android 上使用的)

您可能想要使用 Plus.MomentsApi API,请参阅 https://developers.google.com/+/mobile/android/app-activities

【讨论】:

  • 我试图从用户那里获取帖子,而不是在他们的 google+ 墙上写。这是我在您在重播中链接的文档中找到的内容:“注意:moment 方法不会直接写入用户的 Google+ 流。它们会写入用户的个人资料,并且不一定会被其他人查看,具体取决于用户的偏好共享设置。”我不想“写入用户的个人资料”/