本文整理汇总了Java中org.brickred.socialauth.util.MethodType类的典型用法代码示例。如果您正苦于以下问题:Java MethodType类的具体用法?Java MethodType怎么用?Java MethodType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MethodType类属于org.brickred.socialauth.util包,在下文中一共展示了MethodType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doInBackground
import org.brickred.socialauth.util.MethodType; //导入依赖的package包/类
@SafeVarargs
@Override
protected final Integer doInBackground(Map<String, String>... params) {
// Call using API method of socialauth
Response response;
Map<String, String> paramsMap = params[0];
try {
String UPDATE_STATUS_URL = "https://graph.facebook.com/me/feed";
//noinspection ConstantConditions
response = getCurrentProvider().api(UPDATE_STATUS_URL, MethodType.POST.toString(), paramsMap, null,
storyResult);
Log.d("Status", String.valueOf(response.getStatus()));
return response.getStatus();
} catch (Exception e) {
e.printStackTrace();
dialogListener.onError(new SocialAuthError("Message Not Posted", e));
return null;
}
}
示例2: doVerifyResponse
import org.brickred.socialauth.util.MethodType; //导入依赖的package包/类
private Profile doVerifyResponse(final Map<String, String> requestParams)
throws Exception {
LOG.info("Retrieving Access Token in verify response function");
if (requestParams.get("error") != null
&& "access_denied".equals(requestParams.get("error"))) {
throw new UserDeniedPermissionException();
}
accessGrant = authenticationStrategy.verifyResponse(requestParams,
MethodType.POST.toString());
if (accessGrant != null) {
LOG.debug("Obtaining user profile");
return null;
} else {
throw new SocialAuthException("Access token not found");
}
}
示例3: doVerifyResponse
import org.brickred.socialauth.util.MethodType; //导入依赖的package包/类
private Profile doVerifyResponse(final Map<String, String> requestParams)
throws Exception {
LOG.info("Retrieving Access Token in verify response function");
if (requestParams.get("error_reason") != null
&& "user_denied".equals(requestParams.get("error_reason"))) {
throw new UserDeniedPermissionException();
}
accessGrant = authenticationStrategy.verifyResponse(requestParams,
MethodType.POST.toString());
if (accessGrant != null) {
LOG.debug("Obtaining user profile");
return getProfile();
} else {
throw new SocialAuthException("Access token not found");
}
}
示例4: doVerifyResponse
import org.brickred.socialauth.util.MethodType; //导入依赖的package包/类
private Profile doVerifyResponse(final Map<String, String> requestParams)
throws Exception {
LOG.info("Verifying the authentication response from provider");
if (requestParams.get("error") != null
&& "access_denied".equals(requestParams.get("error"))) {
throw new UserDeniedPermissionException();
}
accessGrant = authenticationStrategy.verifyResponse(requestParams,
MethodType.POST.toString());
if (accessGrant != null) {
LOG.debug("Obtaining user profile");
getUserProfile();
return this.userProfile;
} else {
throw new SocialAuthException("Access token not found");
}
}
示例5: doVerifyResponse
import org.brickred.socialauth.util.MethodType; //导入依赖的package包/类
/**
* @param requestParams
* @return
* @throws Exception
*/
private Profile doVerifyResponse(final Map<String, String> requestParams)
throws Exception {
LOG.info("Retrieving Access Token in verify response function");
if (requestParams.get("error") != null
&& "access_denied".equals(requestParams.get("error"))) {
throw new UserDeniedPermissionException();
}
accessGrant = authenticationStrategy.verifyResponse(requestParams,
MethodType.POST.toString());
if (accessGrant != null) {
LOG.debug("Obtaining user profile");
return getProfile();
} else {
throw new SocialAuthException("Access token not found");
}
}
示例6: doVerifyResponse
import org.brickred.socialauth.util.MethodType; //导入依赖的package包/类
private Profile doVerifyResponse(final Map<String, String> requestParams)
throws Exception {
LOG.info("Retrieving Access Token in verify response function");
if (requestParams.get("error") != null
&& "access_denied".equals(requestParams.get("error"))) {
throw new UserDeniedPermissionException();
}
accessGrant = authenticationStrategy.verifyResponse(requestParams,
MethodType.POST.toString());
if (accessGrant != null) {
LOG.debug("Obtaining user profile");
return getProfile();
} else {
throw new SocialAuthException("Access token not found");
}
}
示例7: uploadImage
import org.brickred.socialauth.util.MethodType; //导入依赖的package包/类
/**
* Updates the image and message on Twitter. Twitter supports only PNG,JPG
* and GIF image formats. Animated GIFs are not supported.
*
* @param message
* Status Message
* @param fileName
* Image file name
* @param inputStream
* Input Stream of image
* @return Response object
* @throws Exception
*/
@Override
public Response uploadImage(final String message, final String fileName,
final InputStream inputStream) throws Exception {
LOG.info("Uploading Image :: " + fileName + ", message :: " + message);
if (!IMAGE_FILE_PATTERN.matcher(fileName).find()) {
throw new SocialAuthException(
"Twitter supports only PNG, JPG and GIF image formats");
}
String fileNameParam = "media[]";
Map<String, String> map = new HashMap<String, String>();
map.put("status", message);
Response response = authenticationStrategy.uploadImage(
IMAGE_UPLOAD_URL, MethodType.POST.toString(), map, null,
fileName, inputStream, fileNameParam);
LOG.info("Upload Image status::" + response.getStatus());
return response;
}
示例8: api
import org.brickred.socialauth.util.MethodType; //导入依赖的package包/类
/**
* Makes OAuth signed HTTP - GET request to a given URL. It attaches
* Authorization header with HTTP request.
*
* @param url
* URL to make HTTP request.
* @param methodType
* Method type should be GET
* @param params
* Not using this parameter in Google API function
* @param headerParams
* Any additional parameters need to pass as Header Parameters
* @param body
* Request Body
* @return Response object
* @throws Exception
*/
@Override
public Response api(final String url, final String methodType,
final Map<String, String> params,
final Map<String, String> headerParams, final String body)
throws Exception {
Response serviceResponse = null;
if (!MethodType.GET.toString().equals(methodType)) {
throw new SocialAuthException(
"Only GET method is implemented in Google API function");
}
LOG.debug("Calling URL : " + url);
try {
serviceResponse = authenticationStrategy.executeFeed(url,
methodType, params, headerParams, body);
} catch (Exception ie) {
throw new SocialAuthException(
"Error while making request to URL : " + url, ie);
}
return serviceResponse;
}
示例9: updateStatus
import org.brickred.socialauth.util.MethodType; //导入依赖的package包/类
/**
* Updates the status on the chosen provider if available. This may not be
* implemented for all providers.
*
* @param msg
* Message to be shown as user's status
* @throws Exception
*/
@Override
public Response updateStatus(final String msg) throws Exception {
if (msg == null || msg.trim().length() == 0) {
throw new ServerDataException("Status cannot be blank");
}
LOG.info("Updating status " + msg + " on " + UPDATE_STATUS_URL);
String msgBody = "{\"status\":\"" + msg + "\"}";
Response serviceResponse = null;
try {
serviceResponse = authenticationStrategy.executeFeed(
UPDATE_STATUS_URL, MethodType.PUT.toString(), null, null,
msgBody);
} catch (Exception ie) {
throw new SocialAuthException("Failed to update status on "
+ UPDATE_STATUS_URL, ie);
}
LOG.info("Update Status Response :" + serviceResponse.getStatus());
return serviceResponse;
}
示例10: doInBackground
import org.brickred.socialauth.util.MethodType; //导入依赖的package包/类
@Override
protected Integer doInBackground(Map<String, String>... params) {
// Call using API method of socialauth
Response response = null;
Map<String, String> paramsMap = params[0];
try {
response = getCurrentProvider().api(UPDATE_STATUS_URL, MethodType.POST.toString(), paramsMap, null,
storyResult);
Log.d("Status", String.valueOf(response.getStatus()));
return Integer.valueOf(response.getStatus());
} catch (Exception e) {
e.printStackTrace();
dialogListener.onError(new SocialAuthError("Message Not Posted", e));
return null;
}
}
示例11: getAlbums
import org.brickred.socialauth.util.MethodType; //导入依赖的package包/类
@Override
public List<Album> getAlbums() throws Exception {
Response response = providerSupport.api(ALBUMS_URL,
MethodType.GET.toString(), null, null, null);
String respStr = response.getResponseBodyAsString(Constants.ENCODING);
LOG.debug("Albums JSON :: " + respStr);
List<Album> albums = new ArrayList<Album>();
JSONObject resp = new JSONObject(respStr);
JSONArray data = resp.getJSONArray("data");
LOG.debug("Albums count : " + data.length());
for (int i = 0; i < data.length(); i++) {
Album album = new Album();
JSONObject obj = data.getJSONObject(i);
String albumId = obj.optString("id", null);
album.setId(albumId);
album.setName(obj.optString("name", null));
album.setLink(obj.optString("link", null));
album.setCoverPhoto(obj.optString("cover_photo", null));
album.setPhotosCount(obj.optInt("count"));
if (albumId != null) {
album.setCoverPhoto(String.format(ALBUM_COVER_URL, albumId,
providerSupport.getAccessGrant().getKey()));
}
List<Photo> photos = getAlbumPhotos(albumId);
album.setPhotos(photos);
albums.add(album);
}
return albums;
}
示例12: getAlbumPhotos
import org.brickred.socialauth.util.MethodType; //导入依赖的package包/类
private List<Photo> getAlbumPhotos(final String id) throws Exception {
Response response = providerSupport.api(
String.format(ALBUM_PHOTOS_URL, id), MethodType.GET.toString(),
null, null, null);
String respStr = response.getResponseBodyAsString(Constants.ENCODING);
LOG.info("Getting Photos of Album :: " + id);
JSONObject resp = new JSONObject(respStr);
JSONArray data = resp.getJSONArray("data");
LOG.debug("Photos count : " + data.length());
List<Photo> photos = new ArrayList<Photo>();
for (int i = 0; i < data.length(); i++) {
Photo photo = new Photo();
JSONObject obj = data.getJSONObject(i);
photo.setId(obj.optString("id", null));
photo.setTitle(obj.optString("name", null));
photo.setLink(obj.optString("link", null));
photo.setThumbImage(obj.optString("picture", null));
JSONArray images = obj.getJSONArray("images");
for (int k = 0; k < images.length(); k++) {
JSONObject img = images.getJSONObject(k);
int ht = 0;
int wt = 0;
if (img.has("height")) {
ht = img.optInt("height");
}
if (img.has("width")) {
wt = img.optInt("width");
}
if (ht == 600 || wt == 600) {
photo.setLargeImage(img.optString("source"));
} else if (ht == 480 || wt == 480) {
photo.setMediumImage(img.optString("source"));
} else if (ht == 320 || wt == 320) {
photo.setSmallImage(img.optString("source"));
}
}
photos.add(photo);
}
return photos;
}
示例13: getUserId
import org.brickred.socialauth.util.MethodType; //导入依赖的package包/类
private String getUserId() throws Exception {
if (this.userId != null) {
return this.userId;
} else {
String profileUrl = String.format(PROFILE_URL, providerSupport
.getAccessGrant().getKey());
Response response = providerSupport.api(profileUrl,
MethodType.GET.toString(), null, null, null);
Element root;
try {
root = XMLParseUtil.loadXmlResource(response.getInputStream());
} catch (Exception e) {
throw new ServerDataException(
"Failed to parse the User from response." + profileUrl,
e);
}
String id = "";
if (root != null) {
NodeList uList = root.getElementsByTagName("user");
if (uList != null && uList.getLength() > 0) {
Element user = (Element) uList.item(0);
id = user.getAttribute("nsid");
}
}
return id;
}
}
示例14: updateStatus
import org.brickred.socialauth.util.MethodType; //导入依赖的package包/类
@Override
public Response updateStatus(final String msg) throws Exception {
if (msg == null || msg.trim().length() == 0) {
throw new ServerDataException("Status cannot be blank");
}
String message = msg;
if (msg.length() > 700) {
LOG.warn("Message length can not be greater than 700 characters. So truncating it to 700 chars");
message = msg.substring(0, 700);
}
// message = URLEncoder.encode(message, Constants.ENCODING);
message = message.replace("&", "&");
LOG.info("Updating status " + message + " on " + UPDATE_STATUS_URL);
Map<String, String> headerParams = new HashMap<String, String>();
headerParams.put("Content-Type", "text/xml;charset=UTF-8");
String msgBody = String.format(STATUS_BODY, message);
Response serviceResponse = null;
try {
serviceResponse = authenticationStrategy.executeFeed(
UPDATE_STATUS_URL
+ authenticationStrategy.getAccessGrant().getKey(),
MethodType.POST.toString(), null, headerParams, msgBody);
} catch (Exception ie) {
throw new SocialAuthException("Failed to update status on "
+ UPDATE_STATUS_URL, ie);
}
LOG.debug("Status Updated and return status code is : "
+ serviceResponse.getStatus());
// return 201
return serviceResponse;
}
示例15: updateStatus
import org.brickred.socialauth.util.MethodType; //导入依赖的package包/类
/**
* Updates the status on the chosen provider if available. This may not be
* implemented for all providers.
*
* @param msg
* Message to be shown as user's status
* @throws Exception
*/
@Override
public Response updateStatus(final String msg) throws Exception {
LOG.info("Updating status : " + msg);
if (!isVerify || accessToken == null) {
throw new SocialAuthException(
"Please call verifyResponse function first to get Access Token and then update status");
}
if (msg == null || msg.trim().length() == 0) {
throw new ServerDataException("Status cannot be blank");
}
Map<String, String> headerParam = new HashMap<String, String>();
headerParam.put("Authorization", "Bearer " + accessToken);
headerParam.put("Content-Type", "application/json");
headerParam.put("Accept", "application/json");
String msgBody = "{\"body\" : \"" + msg + "\"}";
Response serviceResponse;
try {
serviceResponse = HttpUtil.doHttpRequest(UPDATE_STATUS_URL,
MethodType.POST.toString(), msgBody, headerParam);
if (serviceResponse.getStatus() != 201) {
throw new SocialAuthException(
"Status not updated. Return Status code :"
+ serviceResponse.getStatus());
}
} catch (Exception e) {
throw new SocialAuthException(e);
}
return serviceResponse;
}