2

Hi I created an app for a drupal site and everything is working fine as I used the DIOS Library by workhabit the only thing that's missing is voting. I found this link http://drupal.org/node/241453 which got me close to everything working.

I just keep getting a 401 unauthorized in my response headers but I can't figure out why I'm unauthorized as I'm passing the session data and everything any help would be greatly appreciated!

My setVote method from my module looks like this

'actions' => array(
        'setVote' => array(
          'callback' => 'votingapi_service_set_vote',
          'access arguments' => array('edit votes'),
          'args' => array(
          array(
          'name' => 'content_type',
          'type' => 'string',
          'description' => t('Content type'),
          'source' => array('data' => 'content_type'),
          'default value' => 'node',
          ),
          array(
          'name' => 'content_id',
          'type' => 'string',
          'description' => t('Content id'),
          'source' => array('data' => 'content_id'),
          ),
          array(
          'name' => 'vote',
          'type' => 'string',
          'description' => t('Vote'),
          'source' => array('data' => 'value'),
          ),
          array(
          'name' => 'uid',
          'type' => 'string',
          'optional' => TRUE,
          'description' => t('User id'),
          'source' => array('data' => 'uid'),
          ),
        ),
        'return' => 'array',
        'help' => t('Sets vote'),
      ),

So I set up my code in my app like this

NSMutableDictionary *voteData = [NSMutableDictionary new];
            [voteData setValue:@"highdea" forKey:@"content_type"];
            [voteData setValue:nid forKey:@"content_id"];
            [voteData setValue:@"1" forKey:@"vote"];
            [voteData setValue:[[[[DIOSSession sharedSession] user] objectForKey:@"user"] objectForKey:@"uid"] forKey:@"uid"];
            [DIOSVote voteUpDown:voteData success:^(AFHTTPRequestOperation *operation, id responseObject) {
                NSLog(@"%@", responseObject);
            } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                NSLog(@"%@", error);
            }];

And here is the DIOSVote Method which I just created and added to the DIOS library

+ (void)voteUpDown:(NSDictionary *)vote
            success:(void (^)(AFHTTPRequestOperation *operation, id responseObject)) success
            failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error)) failure {

    NSString *path = [NSString stringWithFormat:@"%@/%@", kDiosEndpoint, kDiosBaseVote];

    if ([[DIOSSession sharedSession] signRequests]) {
        [[DIOSSession sharedSession] sendSignedRequestWithPath:path
                                                        method:@"POST"
                                                        params:vote
                                                       success:success
                                                       failure:failure];
    } else {
        [[DIOSSession sharedSession] postPath:path
                                   parameters:vote
                                      success:success
                                      failure:failure];
    }
}

All and all here is my result enter image description here

2

Services voting api has a bug, try changing $votes['votes'] to $votes['value'] in the resource inc file and passing the vote value there.

Current:

function _services_votingapi_resource_set_votes($votes, $criteria) {

  if (empty($votes['entity_id'])) {
    return services_error(t('Missing entity ID.'));
  }

  if (empty($votes['votes'])) {
    return services_error(t('Missing votes amount.'));
  }

  return votingapi_set_votes($votes, $criteria);
}

vs:

function _scmp_services_resource_set_votes($votes, $criteria) {

  if (empty($votes['entity_id'])) {
    return services_error(t('Missing entity ID.'));
  }

  if (empty($votes['value'])) {
    return services_error(t('Missing votes amount.'));
  }

  return votingapi_set_votes($votes, $criteria);
}

You can then test by passing the votes array in the request.

Firefox Poster Voting API Set Votes

  • So it does. That corrected my own immediate problem. Thanks for the clear instructions and screenshot. – RevNoah Feb 10 '14 at 18:32
0

Ended up just being a permissions issue :) had to just check the boxes so that my app had permission to vote sorry for overlooking such a small thing

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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