1

I want to use Services and Profile 2 together.

Like following json code:

request:

http://localhost/api/user/1

response:

{
  "uid": "3",
  "name": "test1",
  "theme": "",
  "signature": "",
  "signature_format": "filtered_html",
  "created": "1393554511",
  "access": "1393562420",
  "login": "1393562420",
  "status": "1",
  "timezone": "Asia/Chongqing",
  "language": "",
  "picture": null,
  "data": false,
  "roles": {
    "2": "authenticated user"
  },
  "rdf_mapping": {
    "rdftype": [
      "sioc:UserAccount"
    ],
    "name": {
      "predicates": [
        "foaf:name"
      ]
    },
    "homepage": {
      "predicates": [
        "foaf:page"
      ],
      "type": "rel"
    }
  },

  "profile 2 field": "test",
  "profile 2 field2": "test",
  "profile 2 field3": "test",
  "profile 2 field4": "test",
  "profile 2 field5": "test",
  "profile 2 field6": "test"
}

I find some code detail in Services Module :

modules/services/resources/user_resource.inc

/**
 * Get user details.
 *
 * @param $uid
 *   UID of the user to be loaded.
 *
 * @return
 *   A user object.
 *
 * @see user_load()
 */
function _user_resource_retrieve($uid) {
  $account = user_load($uid);
  if (empty($account)) {
    return services_error(t('There is no user with ID @uid.', array('@uid' => $uid)), 404);
  }

  services_remove_user_data($account);

  // Everything went right.
  return $account;
}

It seems services invoke user_load() method to get user's default information.

So I think:

  • Can I implement hook_user_load() to load Profile 2 fields?
3
  • Recently, I have used user-profile2 with services for user registration. If required I can share the sample JSON code with you where profile fields also managed at same time. From your question, I am not clear what you exactly want to do with profile2. May 27, 2014 at 5:08
  • @PushpinderRana, thanks for you reply, In RESTful API, there is post, put, can create a user, and update a user. If I create a user with profile2 field, it will can not work.
    – Moon soon
    May 27, 2014 at 6:44
  • Please go through once from this link. drupal.org/node/2267855 May 27, 2014 at 7:01

1 Answer 1

1

You can use the Services Views module to expose the Profile 2 data you need.

Views support for the Services module version 3.x and later.

It has currently two features:
- Create view based resource creating Services display in a view
- Execute any view of the system via views resource call

Demo video http://youtu.be/DZEhJKMeR5w

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.