当前位置: 首页>>代码示例>>Java>>正文


Java GoogleAccountCredential.setSelectedAccount方法代码示例

本文整理汇总了Java中com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.setSelectedAccount方法的典型用法代码示例。如果您正苦于以下问题:Java GoogleAccountCredential.setSelectedAccount方法的具体用法?Java GoogleAccountCredential.setSelectedAccount怎么用?Java GoogleAccountCredential.setSelectedAccount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential的用法示例。


在下文中一共展示了GoogleAccountCredential.setSelectedAccount方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doInBackground

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //导入方法依赖的package包/类
@Override
protected String doInBackground(thenewpotato.blogg.objects.Comment... params){
    thenewpotato.blogg.objects.Comment mComment = params[0];
    GoogleAccountCredential googleAccountCredential =
            GoogleAccountCredential.usingOAuth2(
                    CommentActivity.this,
                    Collections.singleton(
                            "https://www.googleapis.com/auth/blogger")
            );
    googleAccountCredential.setSelectedAccount(mAccount);
    Blogger service = new Blogger.Builder(HTTP_TRANSPORT, JSON_FACTORY, googleAccountCredential)
            .setApplicationName("Blogger")
            .setHttpRequestInitializer(googleAccountCredential)
            .build();
    try {
        Blogger.Posts.Get get = service.posts().get(mComment.blogId, mComment.postId);
        get.setFields("url");
        Post post = get.execute();
        return post.getUrl();
    }catch (IOException e){
        loge(e.getMessage());
    }
    return null;
}
 
开发者ID:thenewpotato,项目名称:Blogg,代码行数:25,代码来源:CommentActivity.java

示例2: doInBackground

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //导入方法依赖的package包/类
@Override
protected BlogList doInBackground(Void... params){
    BlogList result = null;
    try{
        GoogleAccountCredential googleAccountCredential =
                GoogleAccountCredential.usingOAuth2(
                        MainActivity.this,
                        Collections.singleton(
                                "https://www.googleapis.com/auth/blogger")
                );
        googleAccountCredential.setSelectedAccount(mAccount);
        Blogger service = new Blogger.Builder(HTTP_TRANSPORT, JSON_FACTORY, googleAccountCredential)
                .setApplicationName("Blogg")
                .setHttpRequestInitializer(googleAccountCredential)
                .build();
        Blogger.Blogs.ListByUser blogListByUser = service.blogs().listByUser("self");
        result = blogListByUser.execute();
    } catch (IOException e){
        loge("GetListOfBlogTask: IOException, failed!, message= " + e.getMessage());
    }
    return result;
}
 
开发者ID:thenewpotato,项目名称:Blogg,代码行数:23,代码来源:MainActivity.java

示例3: doInBackground

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //导入方法依赖的package包/类
@Override
protected ArrayList<thenewpotato.blogg.objects.Comment> doInBackground(ArrayList<Comment>... params){
    // comments is only a primitive list containing basic information: blogId, postId, id, and inReplyToId
    comments = params[0];

    GoogleAccountCredential googleAccountCredential =
            GoogleAccountCredential.usingOAuth2(
                    mContext,
                    Collections.singleton(
                            "https://www.googleapis.com/auth/blogger")
            );
    googleAccountCredential.setSelectedAccount(mAccount);
    Blogger service = new Blogger.Builder(HTTP_TRANSPORT, JSON_FACTORY, googleAccountCredential)
            .setApplicationName("Blogger")
            .setHttpRequestInitializer(googleAccountCredential)
            .build();
    try {
        for (int i = 0; i < comments.size(); i++) {
            Comment comment = comments.get(i);
            Blogger.Comments.Get getComment = service.comments().get(comment.blogId, comment.postId, comment.id);
            getComment.setFields("author/displayName,updated,content,author/image/url");
            com.google.api.services.blogger.model.Comment resultComment = getComment.execute();
            Blogger.Posts.Get getPost = service.posts().get(comment.blogId, comment.postId);
            getPost.setFields("title");
            replaceCommentItem(i, resultComment, getPost.execute());
        }
    } catch (IOException e){
        loge(e.getMessage());
    }
    return comments;
}
 
开发者ID:thenewpotato,项目名称:Blogg,代码行数:32,代码来源:GetDetailedCommentsTask.java

示例4: doInBackground

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //导入方法依赖的package包/类
@Override
protected List<Person> doInBackground(Account... accounts) {
    if (mActivityRef.get() == null) {
        return null;
    }

    Context context = mActivityRef.get().getApplicationContext();
    try {
        GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(
                context,
                Collections.singleton(CONTACTS_SCOPE));
        credential.setSelectedAccount(accounts[0]);

        PeopleService service = new PeopleService.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
                .setApplicationName("Google Sign In Quickstart")
                .build();

        ListConnectionsResponse connectionsResponse = service
                .people()
                .connections()
                .list("people/me")
                .setPersonFields("names,emailAddresses")
                .execute();

        return connectionsResponse.getConnections();

    } catch (UserRecoverableAuthIOException recoverableException) {
        if (mActivityRef.get() != null) {
            mActivityRef.get().onRecoverableAuthException(recoverableException);
        }
    } catch (IOException e) {
        Log.w(TAG, "getContacts:exception", e);
    }

    return null;
}
 
开发者ID:googlesamples,项目名称:google-services,代码行数:37,代码来源:RestApiActivity.java

示例5: getGoogleCredential

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //导入方法依赖的package包/类
/**
 * Construct auth credential for accessing backend server.
 *
 * @return Server login credential for current user
 */
@NonNull
private GoogleAccountCredential getGoogleCredential() {
    GoogleAccountCredential
            credential = GoogleAccountCredential.usingOAuth2(this, Arrays.asList(
            AccountUtils.AUTH_SCOPES));
    credential.setSelectedAccount(AccountUtils.getActiveAccount(this));
    return credential;
}
 
开发者ID:google,项目名称:iosched,代码行数:14,代码来源:RegistrationStatusService.java

示例6: getGoogleAccountCredential

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //导入方法依赖的package包/类
/**
 * Retrieve the Google account credentials of the currently signed in user.
 *
 * @param context Current context.
 * @return Google account credential if user is signed in null otherwise.
 */
private static GoogleAccountCredential getGoogleAccountCredential(Context context) {
    if (AccountUtils.hasActiveAccount(context)) {
        GoogleAccountCredential credential =
                GoogleAccountCredential
                        .usingOAuth2(context, Arrays.asList(AccountUtils.AUTH_SCOPES));
        credential.setSelectedAccount(AccountUtils.getActiveAccount(context));
        return credential;
    } else {
        return null;
    }
}
 
开发者ID:google,项目名称:iosched,代码行数:18,代码来源:ServerUtilities.java

示例7: getUserdataHandler

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //导入方法依赖的package包/类
/**
 * Returns a {@link Userdata} object that can be used to access the user data endpoint.
 * @param context {@link Context}.
 */
static Userdata getUserdataHandler(Context context) {
    GoogleAccountCredential credential =
            GoogleAccountCredential
                    .usingOAuth2(context, Arrays.asList(AccountUtils.AUTH_SCOPES));
    credential.setSelectedAccount(AccountUtils.getActiveAccount(context));
    return new Userdata.Builder(new NetHttpTransport(),
            new AndroidJsonFactory(), credential).build();
}
 
开发者ID:google,项目名称:iosched,代码行数:13,代码来源:RemoteUserDataHelper.java


注:本文中的com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.setSelectedAccount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。