/*
* Copyright 2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.social.showcase.facebook;
import javax.inject.Inject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.social.connect.ApiAdapter;
import org.springframework.social.connect.Connection;
import org.springframework.social.connect.ConnectionFactoryLocator;
import org.springframework.social.connect.ConnectionRepository;
import org.springframework.social.connect.support.OAuth2ConnectionFactory;
import org.springframework.social.connect.web.ConnectController;
import org.springframework.social.facebook.api.Facebook;
import org.springframework.social.facebook.api.PagedList;
import org.springframework.social.facebook.api.Post;
import org.springframework.social.facebook.api.impl.FacebookTemplate;
import org.springframework.social.oauth2.AccessGrant;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.client.HttpClientErrorException;
@Controller
public class SpensieveConnectController {
Logger log = LoggerFactory.getLogger(this.getClass());
private final ConnectionFactoryLocator connectionFactoryLocator;
private final ConnectionRepository connectionRepository;
@Inject
public SpensieveConnectController(ConnectionFactoryLocator connectionFactoryLocator, ConnectionRepository connectionRepository) {
this.connectionFactoryLocator = connectionFactoryLocator;
this.connectionRepository = connectionRepository;
}
public String run() {
ConnectController cc = new ConnectController(connectionFactoryLocator, connectionRepository);
OAuth2ConnectionFactory<?> connectionFactory = (OAuth2ConnectionFactory<?>) connectionFactoryLocator.getConnectionFactory("facebook");
String acess_token ="CAAUNYZA0M2HcBAGVkKmEkpWyZCBrvkX5samxqb92QKJrDWnr9qnxS0cjxZAo8DH7iZC3v40ETjfCsK78XeNSmtRZCzmgJZCIrGuTCkPL4VK9XmRxtZBRCqOXhZCEZCMlvTq8ery5ZAsSGub3fcHFWp8CZCJRZCciaQeKZCoDDJdR9RZAuZBmrEXB4pPHSgF3WaQw32Pl4MZD";
String expires = "5163679";
AccessGrant accessGrant = new AccessGrant(acess_token, null, null, expires != null ? Long.valueOf(expires) : null);
Connection<?> connection = connectionFactory.createConnection(accessGrant);
Facebook fb =(Facebook) connection.getApi();
FacebookTemplate ft = new FacebookTemplate(fb.getAccessToken(),fb.getApplicationNamespace());
PagedList<Post> pl = ft.feedOperations().getFeed();
Post post = pl.get(0);
log.info(post.getMessage());
return "facebook/profile";
}
}
'etc' 카테고리의 다른 글
명함 (0) | 2014.07.19 |
---|---|
FB 인증토큰 (0) | 2014.07.19 |
Wilson Learning Korea - Social Style Profile (0) | 2014.07.05 |
Backup - Logics (0) | 2014.07.05 |
spring (0) | 2014.06.16 |