Spring Social

本文深入探讨SpringSocial的核心API,包括如何通过服务提供商的API访问或更新用户信息,以及提供了一系列通用操作,如获取用户资料、更新状态等。通过SpringSocial,开发者可以轻松实现与各种服务提供商的集成。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Spring Social的核心API


package org.springframework.social.connect;

/**
* A link to a service provider user.
* Allows the client application to access or update user information using the provider's API.
* Exposes a set of operations that are common across all service providers, including
* the ability to {@link #fetchUserProfile() access user profile information} and {@link #updateStatus(String) update user status}.
* @author Keith Donald
* @param <A> a strongly-typed binding to the service provider's API
*/
public interface Connection<A> {

/**
* The key identifying this connection.
* A composite key that consists of the "providerId" plus "providerUserId"; for example, "facebook" and "125660".
*/
ConnectionKey getKey();

/**
* A display name or label for this connection.
* Should be suitable for display on a UI and distinguish this connection from others with the same provider.
* Generally the full name or screen name of the connected provider user e.g. "Keith Donald" or "@kdonald".
* May be null if this information is not public or not provided.
* The value of this property may change if the user updates his or her profile.
* @see #sync()
*/
String getDisplayName();

/**
* The public URL of the connected user's profile at the provider's site.
* A client application may use this value along with the displayName to generate a link to the user's profile on the provider's system.
* May be null if this information is not public or not provided.
* The value of this property may change if the user updates his or her profile.
* @see #sync()
*/
String getProfileUrl();

/**
* A link to a image that visualizes this connection.
* Should visually distinguish this connection from others with the same provider.
* Generally the small/thumbnail version of the connected provider user's profile picture.
* May be null if this information is not public or not provided.
* The value of this property may change if the user updates his or her profile.
* @see #sync()
*/
String getImageUrl();

/**
* Sync's this connection object with the current state of the external user's profile.
* Triggers locally cached profile fields to update if they have changed on the provider's system.
*/
void sync();

/**
* Test this connection.
* If false, indicates calls to the {@link #getApi() api} will fail.
* Used to proactively test authorization credentials such as an API access token before invoking the service API.
*/
boolean test();

/**
* Returns true if this connection has expired.
* An expired connection cannot be used; calls to {@link #test()} return false, and any service API invocations fail.
* If expired, you may call {@link #refresh()} to renew the connection.
* Not supported by all Connection implementations; always returns false if not supported.
*/
boolean hasExpired();

/**
* Refresh this connection.
* Used to renew an expired connection.
* If the refresh operation is successful, {@link #hasExpired()} returns false.
* Not supported by all connection implementations; if not supported, this method is a no-op.
*/
void refresh();

/**
* Fetch a normalized model of the user's profile on the provider system.
* Capable of exposing the user's name, email, and username.
* What is actually exposed depends on the provider and scope of this connection.
*/
UserProfile fetchUserProfile();

/**
* Update the user's status on the provider's system.
* This method is a no-op if a status concept is not supported by the service provider.
* @param message the status message
*/
void updateStatus(String message);

/**
* A Java binding to the service provider's native API.
*/
A getApi();

/**
* Creates a data transfer object that can be used to persist the state of this connection.
* Used to support the transfer of connection state between layers of the application, such as to the database layer.
*/
ConnectionData createData();

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值