Announcement Announcement Module
Collapse
No announcement yet.
How to use the Facebook Account Api. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to use the Facebook Account Api.

    So Im attempting to use Account
    to retrieve A facebooks user name but everytime I run it it throws a lot of errors and my application wont even start. Most of the errors are resulting from Caused by: org.springframework.beans.factory.NoSuchBeanDefini tionException: No qualifying bean of type [org.springframework.social.facebook.api.Account] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}

    heres the code im using.
    Code:
    import java.util.List;
    
    import javax.inject.Inject;
    
    import org.springframework.social.facebook.api.Facebook;
    import org.springframework.social.facebook.api.PagedList;
    import org.springframework.social.facebook.api.Reference;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.social.facebook.api.Account;
    
    /**
     * Simple little @Controller that invokes Facebook and renders the result.
     * The injected {@link Facebook} reference is configured with the required authorization credentials for the current user behind the scenes.
     * @author Keith Donald
     */
    @Controller
    public class HomeController {
          
    	private final Facebook facebook;
            private final Account account;
            
    	
    	@Inject
    	public HomeController(Facebook facebook, Account account) {
    		this.facebook = facebook;
                    this.account = account;
                    
    	}
    
    
    	@RequestMapping(value = "/", method = RequestMethod.GET)
    	public String home(Model model) {
    		List<Reference> friends = facebook.friendOperations().getFriends();
                    String ID = account.getName();
    		model.addAttribute("friends", friends);
                    DataBase database = new DataBase();
                    database.createDb(friends);
                    database.removeData();
                    database.shutDown();
    		return "home";
    	}
    
    }

  • #2
    It's complaining because there is no bean in the Spring application context of type Account. That's not surprising, because that is not typically how you'd use Account.

    Why are you injecting an Account into the controller? Account isn't a service API...it's a domain type that represents an account for working with Facebook pages.

    I'm not sure what you want to do with an Account, but you'd typically obtain one or more Account objects via PageOperations. If the current user has been authorized to edit or administer a Facebook page (not their own account, but a brand or info page such as https://www.facebook.com/cocacola), then you can call PageOperation's getAccounts() method and get an Account object for each page they are authorized to work with.

    If that's the kind of thing you want to do, then you can call facebook.pageOperations().getAccounts() on the already-injected Facebook object.

    But again, I'm unclear on what your goals are here, so I'm only speculating. What is it that you want to achieve and maybe I can help you more.

    Comment

    Working...
    X